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.3
Syntax
public HeaderFooterCollection HeadersFooters { get; }

Property Value

Type: HeaderFooterCollection
Examples
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.doc");
Examples
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();
}

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