HeaderFooterCollection Class
Provides typed access to HeaderFooter nodes of a Section.
Inheritance Hierarchy
SystemObject
  Aspose.WordsNodeCollection
    Aspose.WordsHeaderFooterCollection

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.11
Syntax
public class HeaderFooterCollection : NodeCollection

The HeaderFooterCollection type exposes the following members.

Properties
Methods
  NameDescription
Public methodCode exampleAdd
Adds a node to the end of the collection.
(Inherited from NodeCollection.)
Public methodCode exampleClear
Removes all nodes from this collection and from the document.
(Inherited from NodeCollection.)
Public methodCode exampleContains
Determines whether a node is in the collection.
(Inherited from NodeCollection.)
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetEnumerator (Inherited from NodeCollection.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleIndexOf
Returns the zero-based index of the specified node.
(Inherited from NodeCollection.)
Public methodCode exampleInsert
Inserts a node into the collection at the specified index.
(Inherited from NodeCollection.)
Public methodCode exampleLinkToPrevious(Boolean)
Links or unlinks all headers and footers to the corresponding headers and footers in the previous section.
Public methodCode exampleLinkToPrevious(HeaderFooterType, Boolean)
Links or unlinks the specified header or footer to the corresponding header or footer in the previous section.
Protected methodMemberwiseClone (Inherited from Object.)
Public methodCode exampleRemove
Removes the node from the collection and from the document.
(Inherited from NodeCollection.)
Public methodCode exampleRemoveAt
Removes the node at the specified index from the collection and from the document.
(Inherited from NodeCollection.)
Public methodCode exampleToArray
Copies all HeaderFoorters from the collection to a new array of HeaderFoorters.
Public methodToString (Inherited from Object.)
Remarks

There can be maximum of one HeaderFooter

of each HeaderFooterType per Section.

HeaderFooter objects can occur in any order in the collection.

Examples
Deletes all footers from all sections, but leaves headers intact.
Document doc = new Document(MyDir + "HeaderFooter.RemoveFooters.doc");

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.doc");
Examples
Creates a header and footer using the document object model and insert them into a section.
Document doc = new Document();

HeaderFooter header = new HeaderFooter(doc, HeaderFooterType.HeaderPrimary);
doc.FirstSection.HeadersFooters.Add(header);

// Add a paragraph with text to the footer.
Paragraph para = header.AppendParagraph("My header");

Assert.True(header.IsHeader);
Assert.True(para.IsEndOfHeaderFooter);

HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FooterPrimary);
doc.FirstSection.HeadersFooters.Add(footer);

// Add a paragraph with text to the footer.
para = footer.AppendParagraph("My footer");

Assert.False(footer.IsHeader);
Assert.True(para.IsEndOfHeaderFooter);

Assert.AreEqual(footer, para.ParentStory);
Assert.AreEqual(footer.ParentSection, para.ParentSection);
Assert.AreEqual(footer.ParentSection, header.ParentSection);

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