Header and footer being used on EVERY appended document

Using the code below:

If File.Exists(doc.DocumentPath & doc.DocumentName) Then
document.AppendDocument(tempDoc, ImportFormatMode.KeepSourceFormatting)
document.UpdatePageLayout()
End If
'document.Save("c:\temp_

to append documents together. The document filenames are held in a database which also has a use logo flag. This is set to true and false for different docuemnts.

However if the first document has a header with a logo in it, it is used on ever other page.

I have removed the headers:

Dim h As Aspose.Words.SectionCollection
h = document.Sections
For Each dh In h
dh.HeadersFooters(HeaderFooterType.HeaderFirst).Remove()
dh.HeadersFooters(HeaderFooterType.HeaderPrimary).Remove()
Next

But it then has no header on any of the docs.

SO… how can I control headers and footers as I append documents…

Thnaks

Hi there,

Thanks for your inquiry. Please use HeaderFooterCollection.LinkToPrevious method (Boolean) to link or unlink all headers and footers to the corresponding headers and footers in the previous section. I suggest you please read following documentation link for your kind reference.
https://docs.aspose.com/words/net/working-with-headers-and-footers/

Following code example shows how to append a document to another document so headers and footers do not continue from the destination document.

Document dstDoc = new Document(gDataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(gDataDir + "TestFile.Source.doc");
// Even a document with no headers or footers can still have the LinkToPrevious setting set to true.
// Unlink the headers and footers in the source document to stop this from continuing the headers and footers
// from the destination document.
srcDoc.FirstSection.HeadersFooters.LinkToPrevious(false);
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(gDataDir + "TestFile.UnlinkHeadersFooters Out.doc");

Excellent!
All fixed! Thanks for the quick response.
Che

Hi there,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.