We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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)
End If

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

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

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


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.

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.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(gDataDir + "TestFile.UnlinkHeadersFooters Out.doc");

All fixed! Thanks for the quick response.

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.