Hi,
How can I check if a header is linked to previous when it’s placed in a different section. In attached document in the first section the HeaderFooter property “IsLinkedToPrevious” is false for every entry. In the second section the HeaderFooter collection is empty.
Regards
watermarkHeaders.zip (24.5 KB)
@lars.olsson,
Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does.
In this case, the HeaderFooter is linked to previous section. You can check empty HeaderFooter collection using Section.HeadersFooters.Count property.
If you do not want to view same header footer for second section, please use the following code example. Hope this helps you.
Document doc = new Document(MyDir + "watermarkHeaders.docx");
//Get the second section
Section section = doc.Sections[1];
HeaderFooter header = section.HeadersFooters[HeaderFooterType.HeaderPrimary];
if (header == null)
{
// There is no header of the specified type in the current section, create it.
header = new HeaderFooter(doc, HeaderFooterType.HeaderPrimary);
section.HeadersFooters.Add(header);
header.IsLinkedToPrevious = false;
}
doc.Save(MyDir + "output.docx");