HeaderFooterCollectionItem Property (HeaderFooterType)

Retrieves a HeaderFooter of the specified type.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public HeaderFooter this[
	HeaderFooterType headerFooterType
] { get; }

Parameters

headerFooterType
Type: Aspose.WordsHeaderFooterType
A HeaderFooterType value that specifies the type of the header/footer to retrieve.

Property Value

Type: HeaderFooter
Remarks
Returns null if the header/footer of the specified type is not found.
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