Word OpenXML change relationship id and uri for imagePart?How do you display code snippets in MS Word preserving format and syntax highlighting?Inserting newlines in Word using OpenXMLI am merging two Word documents with OpenXML SDK but get a corrupt document when copying an image into a headerClone ParagraphProperties in Word using OpenXml SDK 2.0Word OpenXML replace token textC# OpenXML (Word) Table AutoFit to WindowCreating an ImagePart isn't saving the Relationship in OpenXMLOpenXml Word FootnotesInsert picture to header of Word document with OpenXMLOpenXML - Remove TableCaption in Word doc
What is the German equivalent of the proverb 水清ければ魚棲まず (if the water is clear, fish won't live there)?
What would the United Kingdom's "optimal" Brexit deal look like?
Should I accept an invitation to give a talk from someone who might review my proposal?
Why tantalum for the Hayabusa bullets?
Can a machine benefit from stored heat energy?
Did Vladimir Lenin have a cat?
How does a poisoned arrow combine with the spell Conjure Barrage?
How can Paypal know my card is being used in another account?
Why does aggregate initialization not work anymore since C++20 if a constructor is explicitly defaulted or deleted?
Why does the Eurostar not show youth pricing?
How do I make my photos have more impact?
How long does it take for electricity to be considered OFF by general appliances?
Wrapping IMemoryCache with SemaphoreSlim
How did astronauts using rovers tell direction without compasses on the Moon?
How well would the Moon protect the Earth from an Asteroid?
Why is it "on the inside" and not "in the inside"?
What language is Raven using for her attack in the new 52?
Why does Canada require bilingualism in a lot of federal government posts?
Why did some Apollo missions carry a grenade launcher?
What is the reason for cards stating "Until end of turn, you don't lose this mana as steps and phases end"?
Why is it considered acid rain with pH <5.6?
Shouldn't there be "us" instead of "our" in this sentence?
Do the books ever say oliphaunts aren’t elephants?
What is a good example for artistic ND filter applications?
Word OpenXML change relationship id and uri for imagePart?
How do you display code snippets in MS Word preserving format and syntax highlighting?Inserting newlines in Word using OpenXMLI am merging two Word documents with OpenXML SDK but get a corrupt document when copying an image into a headerClone ParagraphProperties in Word using OpenXml SDK 2.0Word OpenXML replace token textC# OpenXML (Word) Table AutoFit to WindowCreating an ImagePart isn't saving the Relationship in OpenXMLOpenXml Word FootnotesInsert picture to header of Word document with OpenXMLOpenXML - Remove TableCaption in Word doc
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Hi how can I change the realationship and the uri.
I want to merge footer and header from different files but the uri and relationship id is the same in this case /word/media/image1.png in both files and rId1.
What I want is before merging the documents I want to change all relationship with a unique GUID. and the uri should be something like
/word/media/rIddb654056-f112-4695-b38b-0f4f5f81a1ed.png
What is happening now is that only 1 image get transfered to the destination document.
public void ReplaceBlipRealtionShip(HeaderPart part)
foreach (var imgPart in part.GetPartsOfType<ImagePart>().Take(1).ToList())
var existingId = part.GetIdOfPart(imgPart);
var blip = part.Header.Descendants<A.Blip>()
.Where(x => x.Embed.Value == existingId).FirstOrDefault();
if (blip != null)
var newId = OpenXmlGenericHelper.GenerateUniqueRId();
var extension = Path.GetExtension(imgPart.Uri.ToString());
Uri imageUri = new Uri($"/word/media/newId.extension", UriKind.Relative);
// Create "image" part in /word/media
// Change content type for other image types.
var packageImagePart =
WordDoc.Package.CreatePart(imageUri, imgPart.ContentType);
imgPart.GetStream().CopyTo(packageImagePart.GetStream());
var packagePart = part.OpenXmlPackage.Package.GetPart(part.Uri);
var imageReleationshipPart = packagePart.CreateRelationship(
new Uri($"/word/media/newId.extension", UriKind.Relative),
motpackaging::System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image");
//part.ChangeIdOfPart(imgPart, newId);
this.WordDoc.Save();
Extra code:
private List<KeyValuePair<Type, Stream>> CopyParts(OpenXmlPart srcPart, OpenXmlPart destPart)
if(srcPart is HeaderPart)
ReplaceBlipRealtionShip((HeaderPart)srcPart);
var listToAdd = new List<KeyValuePair<Type, Stream>>();
foreach (var idPart in srcPart.Parts)
var part = srcPart.GetPartById(idPart.RelationshipId);
if (part is ImagePart)
var newPart = destPart.AddNewPart<ImagePart>(part.ContentType, idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(ImagePart), part.GetStream()));
else if (part is DiagramStylePart)
destPart.AddNewPart<DiagramStylePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramStylePart), part.GetStream()));
else if (part is DiagramColorsPart)
destPart.AddNewPart<DiagramColorsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramColorsPart),
part.GetStream()));
else if (part is DiagramDataPart)
destPart.AddNewPart<DiagramDataPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramDataPart), part.GetStream()));
else if (part is DiagramPersistLayoutPart)
destPart.AddNewPart<DiagramPersistLayoutPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramPersistLayoutPart),
part.GetStream()));
else if (part is StyleDefinitionsPart)
destPart.AddNewPart<StyleDefinitionsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(StyleDefinitionsPart),
part.GetStream()));
else if (part is StylesWithEffectsPart)
destPart.AddNewPart<StylesWithEffectsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(StylesWithEffectsPart),
part.GetStream()));
else if (part is ThemePart)
destPart.AddNewPart<ThemePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(ThemePart),
part.GetStream()));
else if (part is PivotTablePart)
destPart.AddNewPart<PivotTablePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(PivotTablePart),
part.GetStream()));
else if (part is TableDefinitionPart)
destPart.AddNewPart<TableDefinitionPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(TableDefinitionPart),
part.GetStream()));
else if (part is TableStylesPart)
destPart.AddNewPart<TableStylesPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(TableStylesPart),
part.GetStream()));
return listToAdd;
private void _PrependHeader(HeaderPart srcHeaderPart, HeaderPart destHeaderPart, MainDocumentPart destMainPart)
if (srcHeaderPart != null)
// Copy content of header to new header
destHeaderPart.FeedData(srcHeaderPart.GetStream());
if (destHeaderPart.Header != null)
// Keep formatting
KeepParagraphStyle(destHeaderPart.Header);
// Get all ids of every 'Parts'
var listToAdd = CopyParts(srcHeaderPart, destHeaderPart);
// Foreach Part, copy stream to new header
var i = 0;
foreach (var idPart in destHeaderPart.Parts)
var part = destHeaderPart.GetPartById(idPart.RelationshipId);
if (part.GetType() == listToAdd[i].Key)
part.FeedData(listToAdd[i].Value);
i++;
else
destMainPart.DeleteParts(destMainPart.HeaderParts);
var sectToRemovePrs = destMainPart.Document.Body.Descendants<SectionProperties>();
foreach (var sectPr in sectToRemovePrs)
// Delete reference of old header
sectPr.RemoveAllChildren<HeaderReference>();
c# ms-word openxml openxml-sdk
add a comment |
Hi how can I change the realationship and the uri.
I want to merge footer and header from different files but the uri and relationship id is the same in this case /word/media/image1.png in both files and rId1.
What I want is before merging the documents I want to change all relationship with a unique GUID. and the uri should be something like
/word/media/rIddb654056-f112-4695-b38b-0f4f5f81a1ed.png
What is happening now is that only 1 image get transfered to the destination document.
public void ReplaceBlipRealtionShip(HeaderPart part)
foreach (var imgPart in part.GetPartsOfType<ImagePart>().Take(1).ToList())
var existingId = part.GetIdOfPart(imgPart);
var blip = part.Header.Descendants<A.Blip>()
.Where(x => x.Embed.Value == existingId).FirstOrDefault();
if (blip != null)
var newId = OpenXmlGenericHelper.GenerateUniqueRId();
var extension = Path.GetExtension(imgPart.Uri.ToString());
Uri imageUri = new Uri($"/word/media/newId.extension", UriKind.Relative);
// Create "image" part in /word/media
// Change content type for other image types.
var packageImagePart =
WordDoc.Package.CreatePart(imageUri, imgPart.ContentType);
imgPart.GetStream().CopyTo(packageImagePart.GetStream());
var packagePart = part.OpenXmlPackage.Package.GetPart(part.Uri);
var imageReleationshipPart = packagePart.CreateRelationship(
new Uri($"/word/media/newId.extension", UriKind.Relative),
motpackaging::System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image");
//part.ChangeIdOfPart(imgPart, newId);
this.WordDoc.Save();
Extra code:
private List<KeyValuePair<Type, Stream>> CopyParts(OpenXmlPart srcPart, OpenXmlPart destPart)
if(srcPart is HeaderPart)
ReplaceBlipRealtionShip((HeaderPart)srcPart);
var listToAdd = new List<KeyValuePair<Type, Stream>>();
foreach (var idPart in srcPart.Parts)
var part = srcPart.GetPartById(idPart.RelationshipId);
if (part is ImagePart)
var newPart = destPart.AddNewPart<ImagePart>(part.ContentType, idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(ImagePart), part.GetStream()));
else if (part is DiagramStylePart)
destPart.AddNewPart<DiagramStylePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramStylePart), part.GetStream()));
else if (part is DiagramColorsPart)
destPart.AddNewPart<DiagramColorsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramColorsPart),
part.GetStream()));
else if (part is DiagramDataPart)
destPart.AddNewPart<DiagramDataPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramDataPart), part.GetStream()));
else if (part is DiagramPersistLayoutPart)
destPart.AddNewPart<DiagramPersistLayoutPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramPersistLayoutPart),
part.GetStream()));
else if (part is StyleDefinitionsPart)
destPart.AddNewPart<StyleDefinitionsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(StyleDefinitionsPart),
part.GetStream()));
else if (part is StylesWithEffectsPart)
destPart.AddNewPart<StylesWithEffectsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(StylesWithEffectsPart),
part.GetStream()));
else if (part is ThemePart)
destPart.AddNewPart<ThemePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(ThemePart),
part.GetStream()));
else if (part is PivotTablePart)
destPart.AddNewPart<PivotTablePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(PivotTablePart),
part.GetStream()));
else if (part is TableDefinitionPart)
destPart.AddNewPart<TableDefinitionPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(TableDefinitionPart),
part.GetStream()));
else if (part is TableStylesPart)
destPart.AddNewPart<TableStylesPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(TableStylesPart),
part.GetStream()));
return listToAdd;
private void _PrependHeader(HeaderPart srcHeaderPart, HeaderPart destHeaderPart, MainDocumentPart destMainPart)
if (srcHeaderPart != null)
// Copy content of header to new header
destHeaderPart.FeedData(srcHeaderPart.GetStream());
if (destHeaderPart.Header != null)
// Keep formatting
KeepParagraphStyle(destHeaderPart.Header);
// Get all ids of every 'Parts'
var listToAdd = CopyParts(srcHeaderPart, destHeaderPart);
// Foreach Part, copy stream to new header
var i = 0;
foreach (var idPart in destHeaderPart.Parts)
var part = destHeaderPart.GetPartById(idPart.RelationshipId);
if (part.GetType() == listToAdd[i].Key)
part.FeedData(listToAdd[i].Value);
i++;
else
destMainPart.DeleteParts(destMainPart.HeaderParts);
var sectToRemovePrs = destMainPart.Document.Body.Descendants<SectionProperties>();
foreach (var sectPr in sectToRemovePrs)
// Delete reference of old header
sectPr.RemoveAllChildren<HeaderReference>();
c# ms-word openxml openxml-sdk
add a comment |
Hi how can I change the realationship and the uri.
I want to merge footer and header from different files but the uri and relationship id is the same in this case /word/media/image1.png in both files and rId1.
What I want is before merging the documents I want to change all relationship with a unique GUID. and the uri should be something like
/word/media/rIddb654056-f112-4695-b38b-0f4f5f81a1ed.png
What is happening now is that only 1 image get transfered to the destination document.
public void ReplaceBlipRealtionShip(HeaderPart part)
foreach (var imgPart in part.GetPartsOfType<ImagePart>().Take(1).ToList())
var existingId = part.GetIdOfPart(imgPart);
var blip = part.Header.Descendants<A.Blip>()
.Where(x => x.Embed.Value == existingId).FirstOrDefault();
if (blip != null)
var newId = OpenXmlGenericHelper.GenerateUniqueRId();
var extension = Path.GetExtension(imgPart.Uri.ToString());
Uri imageUri = new Uri($"/word/media/newId.extension", UriKind.Relative);
// Create "image" part in /word/media
// Change content type for other image types.
var packageImagePart =
WordDoc.Package.CreatePart(imageUri, imgPart.ContentType);
imgPart.GetStream().CopyTo(packageImagePart.GetStream());
var packagePart = part.OpenXmlPackage.Package.GetPart(part.Uri);
var imageReleationshipPart = packagePart.CreateRelationship(
new Uri($"/word/media/newId.extension", UriKind.Relative),
motpackaging::System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image");
//part.ChangeIdOfPart(imgPart, newId);
this.WordDoc.Save();
Extra code:
private List<KeyValuePair<Type, Stream>> CopyParts(OpenXmlPart srcPart, OpenXmlPart destPart)
if(srcPart is HeaderPart)
ReplaceBlipRealtionShip((HeaderPart)srcPart);
var listToAdd = new List<KeyValuePair<Type, Stream>>();
foreach (var idPart in srcPart.Parts)
var part = srcPart.GetPartById(idPart.RelationshipId);
if (part is ImagePart)
var newPart = destPart.AddNewPart<ImagePart>(part.ContentType, idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(ImagePart), part.GetStream()));
else if (part is DiagramStylePart)
destPart.AddNewPart<DiagramStylePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramStylePart), part.GetStream()));
else if (part is DiagramColorsPart)
destPart.AddNewPart<DiagramColorsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramColorsPart),
part.GetStream()));
else if (part is DiagramDataPart)
destPart.AddNewPart<DiagramDataPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramDataPart), part.GetStream()));
else if (part is DiagramPersistLayoutPart)
destPart.AddNewPart<DiagramPersistLayoutPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramPersistLayoutPart),
part.GetStream()));
else if (part is StyleDefinitionsPart)
destPart.AddNewPart<StyleDefinitionsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(StyleDefinitionsPart),
part.GetStream()));
else if (part is StylesWithEffectsPart)
destPart.AddNewPart<StylesWithEffectsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(StylesWithEffectsPart),
part.GetStream()));
else if (part is ThemePart)
destPart.AddNewPart<ThemePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(ThemePart),
part.GetStream()));
else if (part is PivotTablePart)
destPart.AddNewPart<PivotTablePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(PivotTablePart),
part.GetStream()));
else if (part is TableDefinitionPart)
destPart.AddNewPart<TableDefinitionPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(TableDefinitionPart),
part.GetStream()));
else if (part is TableStylesPart)
destPart.AddNewPart<TableStylesPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(TableStylesPart),
part.GetStream()));
return listToAdd;
private void _PrependHeader(HeaderPart srcHeaderPart, HeaderPart destHeaderPart, MainDocumentPart destMainPart)
if (srcHeaderPart != null)
// Copy content of header to new header
destHeaderPart.FeedData(srcHeaderPart.GetStream());
if (destHeaderPart.Header != null)
// Keep formatting
KeepParagraphStyle(destHeaderPart.Header);
// Get all ids of every 'Parts'
var listToAdd = CopyParts(srcHeaderPart, destHeaderPart);
// Foreach Part, copy stream to new header
var i = 0;
foreach (var idPart in destHeaderPart.Parts)
var part = destHeaderPart.GetPartById(idPart.RelationshipId);
if (part.GetType() == listToAdd[i].Key)
part.FeedData(listToAdd[i].Value);
i++;
else
destMainPart.DeleteParts(destMainPart.HeaderParts);
var sectToRemovePrs = destMainPart.Document.Body.Descendants<SectionProperties>();
foreach (var sectPr in sectToRemovePrs)
// Delete reference of old header
sectPr.RemoveAllChildren<HeaderReference>();
c# ms-word openxml openxml-sdk
Hi how can I change the realationship and the uri.
I want to merge footer and header from different files but the uri and relationship id is the same in this case /word/media/image1.png in both files and rId1.
What I want is before merging the documents I want to change all relationship with a unique GUID. and the uri should be something like
/word/media/rIddb654056-f112-4695-b38b-0f4f5f81a1ed.png
What is happening now is that only 1 image get transfered to the destination document.
public void ReplaceBlipRealtionShip(HeaderPart part)
foreach (var imgPart in part.GetPartsOfType<ImagePart>().Take(1).ToList())
var existingId = part.GetIdOfPart(imgPart);
var blip = part.Header.Descendants<A.Blip>()
.Where(x => x.Embed.Value == existingId).FirstOrDefault();
if (blip != null)
var newId = OpenXmlGenericHelper.GenerateUniqueRId();
var extension = Path.GetExtension(imgPart.Uri.ToString());
Uri imageUri = new Uri($"/word/media/newId.extension", UriKind.Relative);
// Create "image" part in /word/media
// Change content type for other image types.
var packageImagePart =
WordDoc.Package.CreatePart(imageUri, imgPart.ContentType);
imgPart.GetStream().CopyTo(packageImagePart.GetStream());
var packagePart = part.OpenXmlPackage.Package.GetPart(part.Uri);
var imageReleationshipPart = packagePart.CreateRelationship(
new Uri($"/word/media/newId.extension", UriKind.Relative),
motpackaging::System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image");
//part.ChangeIdOfPart(imgPart, newId);
this.WordDoc.Save();
Extra code:
private List<KeyValuePair<Type, Stream>> CopyParts(OpenXmlPart srcPart, OpenXmlPart destPart)
if(srcPart is HeaderPart)
ReplaceBlipRealtionShip((HeaderPart)srcPart);
var listToAdd = new List<KeyValuePair<Type, Stream>>();
foreach (var idPart in srcPart.Parts)
var part = srcPart.GetPartById(idPart.RelationshipId);
if (part is ImagePart)
var newPart = destPart.AddNewPart<ImagePart>(part.ContentType, idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(ImagePart), part.GetStream()));
else if (part is DiagramStylePart)
destPart.AddNewPart<DiagramStylePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramStylePart), part.GetStream()));
else if (part is DiagramColorsPart)
destPart.AddNewPart<DiagramColorsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramColorsPart),
part.GetStream()));
else if (part is DiagramDataPart)
destPart.AddNewPart<DiagramDataPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramDataPart), part.GetStream()));
else if (part is DiagramPersistLayoutPart)
destPart.AddNewPart<DiagramPersistLayoutPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(DiagramPersistLayoutPart),
part.GetStream()));
else if (part is StyleDefinitionsPart)
destPart.AddNewPart<StyleDefinitionsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(StyleDefinitionsPart),
part.GetStream()));
else if (part is StylesWithEffectsPart)
destPart.AddNewPart<StylesWithEffectsPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(StylesWithEffectsPart),
part.GetStream()));
else if (part is ThemePart)
destPart.AddNewPart<ThemePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(ThemePart),
part.GetStream()));
else if (part is PivotTablePart)
destPart.AddNewPart<PivotTablePart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(PivotTablePart),
part.GetStream()));
else if (part is TableDefinitionPart)
destPart.AddNewPart<TableDefinitionPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(TableDefinitionPart),
part.GetStream()));
else if (part is TableStylesPart)
destPart.AddNewPart<TableStylesPart>(idPart.RelationshipId);
listToAdd.Add(new KeyValuePair<Type, Stream>(typeof(TableStylesPart),
part.GetStream()));
return listToAdd;
private void _PrependHeader(HeaderPart srcHeaderPart, HeaderPart destHeaderPart, MainDocumentPart destMainPart)
if (srcHeaderPart != null)
// Copy content of header to new header
destHeaderPart.FeedData(srcHeaderPart.GetStream());
if (destHeaderPart.Header != null)
// Keep formatting
KeepParagraphStyle(destHeaderPart.Header);
// Get all ids of every 'Parts'
var listToAdd = CopyParts(srcHeaderPart, destHeaderPart);
// Foreach Part, copy stream to new header
var i = 0;
foreach (var idPart in destHeaderPart.Parts)
var part = destHeaderPart.GetPartById(idPart.RelationshipId);
if (part.GetType() == listToAdd[i].Key)
part.FeedData(listToAdd[i].Value);
i++;
else
destMainPart.DeleteParts(destMainPart.HeaderParts);
var sectToRemovePrs = destMainPart.Document.Body.Descendants<SectionProperties>();
foreach (var sectPr in sectToRemovePrs)
// Delete reference of old header
sectPr.RemoveAllChildren<HeaderReference>();
c# ms-word openxml openxml-sdk
c# ms-word openxml openxml-sdk
asked Mar 26 at 20:31
XzaRXzaR
1271 silver badge10 bronze badges
1271 silver badge10 bronze badges
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365751%2fword-openxml-change-relationship-id-and-uri-for-imagepart%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365751%2fword-openxml-change-relationship-id-and-uri-for-imagepart%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown