Insertdocument kills header

I’m adding a whole document to another document using builder. First I create a section, add some headers/footers, and then call InsertDocument. And it kills header and footer at that section.

There is my code:

builder.InsertBreak(BreakType.SectionBreakNewPage);
currentSection = builder.CurrentSection;
pageSetup = currentSection.PageSetup;
pageSetup.DifferentFirstPageHeaderFooter = false;
currentSection.HeadersFooters.LinkToPrevious(false);

// header
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.StartTable();
// some stuff here
var table = builder.EndTable();
table.ClearBorders();

// content
builder.MoveToDocumentEnd();

var doc = new Aspose.Words.Document(data.result.resultFileName);
builder.InsertDocument(doc, ImportFormatMode.UseDestinationStyles, new ImportFormatOptions() { 
IgnoreHeaderFooter = true,
KeepSourceNumbering = false,
SmartStyleBehavior = true,
});

@emfbd33,
I’m afraid, we don’t fully understand your query. Do you want to keep your created footer in the inserted document? If so, please copy your created footer and then add it to the inserted section:

// header
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.StartTable();
// some stuff here
var table = builder.EndTable();
table.ClearBorders();

HeaderFooter oldFooterPrimary = builder.CurrentSection.HeadersFooters[HeaderFooterType.FooterPrimary];

// content
builder.MoveToDocumentEnd();

var doc = new Aspose.Words.Document(data.result.resultFileName);
doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].Remove();

builder.InsertDocument(doc, ImportFormatMode.UseDestinationStyles, new ImportFormatOptions() 
{ 
    IgnoreHeaderFooter = true,
    KeepSourceNumbering = false,
    SmartStyleBehavior = true,
});
builder.CurrentSection.HeadersFooters.Add(oldFooterPrimary);

Ok, so I need to save the footer before inserting the doc and then restore it. I’ll try.

Just don’t get why it’s even overridden in the first place when IgnoreHeaderFooter is used.

@emfbd33,
The ImportFormatOptions.IgnoreHeaderFooter property is used to specify if the source formatting of headers/footers content is ignored. The headers and footers themselves are inserted anyway.

it worked, thanks!