SectionHeadersFooters Property

Provides access to the headers and footers nodes of the section.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.10.0

ExpandedSyntax

public HeaderFooterCollection HeadersFooters { get; }

Property Value

Type: HeaderFooterCollection

ExpandedExamples

Shows how to replace text in the document footer.
// Open the template document, containing obsolete copyright information in the footer
Document doc = new Document(MyDir + "Footer.docx");

HeaderFooterCollection headersFooters = doc.FirstSection.HeadersFooters;
HeaderFooter footer = headersFooters[HeaderFooterType.FooterPrimary];

FindReplaceOptions options = new FindReplaceOptions
{
    MatchCase = false,
    FindWholeWordsOnly = false
};

int currentYear = System.DateTime.Now.Year;
footer.Range.Replace("(C) 2006 Aspose Pty Ltd.", $"Copyright (C) {currentYear} by Aspose Pty Ltd.", options);

doc.Save(ArtifactsDir + "HeaderFooter.ReplaceText.docx");
Deletes all footers from all sections, but leaves headers intact.
Document doc = new Document(MyDir + "Header and footer types.docx");

foreach (Section section in doc.OfType<Section>())
{
    // Up to three different footers are possible in a section (for first, even and odd pages)
    // We check and delete all of them
    HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterFirst];
    footer?.Remove();

    // Primary footer is the footer used for odd pages
    footer = section.HeadersFooters[HeaderFooterType.FooterPrimary];
    footer?.Remove();

    footer = section.HeadersFooters[HeaderFooterType.FooterEven];
    footer?.Remove();

    // All footers have been removed from the section's HeaderFooter collection,
    // so every remaining node is a header and has the "IsHeader" flag set to true 
    Assert.AreEqual(0, section.HeadersFooters.Count(hf => !((HeaderFooter)hf).IsHeader));
}

doc.Save(ArtifactsDir + "HeaderFooter.RemoveFooters.docx");

ExpandedSee Also