HeaderFooterCollection Class
Provides typed access to HeaderFooter nodes of a Section.
Inheritance Hierarchy

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

The HeaderFooterCollection type exposes the following members.

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 methodContains
Determines whether a node is in the collection.
(Inherited from NodeCollection.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator (Inherited from NodeCollection.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodCode exampleIndexOf
Returns the zero-based index of the specified node.
(Inherited from NodeCollection.)
Public methodInsert
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
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRemove
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
Returns a string that represents the current object.
(Inherited from Object.)

There can be maximum of one HeaderFooter

of each HeaderFooterType per Section.

HeaderFooter objects can occur in any order in the collection.

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];

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

    footer = section.HeadersFooters[HeaderFooterType.FooterEven];

doc.Save(ArtifactsDir + "HeaderFooter.RemoveFooters.doc");
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);

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


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

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


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