Aspose words insertdocument() method doesn't retain header/footer on the source document

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.

builder.InsertDocument(docFoot, ImportFormatMode.KeepSourceFormatting);

Attached the document that trying to insert:
TTRO_HEADER.zip (76.6 KB)

@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");

Thanks for the quick reply Alexey,

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.

@Remus87 To retain headers/footers is it required to retain section where these headers/footers are defined. Please see our documentation to learn more about Aspose.Words Document Object Model:
https://docs.aspose.com/words/net/aspose-words-document-object-model/

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.