Just trying to Insert document on the usual way on a DocumentBuilder instance and noticed that doesn’t keep the header and footer elements of the newly inserted document.
@Remus87 When you use InsertDocument method, section from the original document is not preserved, only content is inserted into the current section in the document. So in this case headers/footers are not preserved. In your case it would be more correct to use AppendDocument method to preserve section from the source document including headers/footers. For example see the following code:
Document dst = new Document(@"C:\Temp\NewDoc.docx");
Document src = new Document(@"C:\Temp\CurrentDoc.docx");
dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);
dst.Save(@"C:\Temp\out.docx");
Is there no other alternative to preserve the headers with Insert method?
Asking because if we use Append we’ll have to change quite a bit of code since the append only appends the source document at the beginning of the document.
So you should insert section break where the document should be inserted and then copy whole sections from the source document into the destination placing them after the created section break.