SectionCollection Class
A collection of Section objects in the document.
Inheritance Hierarchy

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

The SectionCollection type exposes the following members.

Public propertyCode exampleCount
Gets the number of nodes in the collection.
(Inherited from NodeCollection.)
Public propertyCode exampleItem
Retrieves a section at the given index.
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.)
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 methodToArray
Copies all sections from the collection to a new array of sections.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)

A Microsoft Word document can contain multiple sections. To create a section in a Microsoft Word, select the Insert/Break command and select a break type. The break specifies whether section starts on a new page or on the same page.

Programmatically inserting and removing sections can be used to customize documents produced during mail merge. If a document needs to have different content or parts of the content depending on some criteria, then you can create a "master" document that contains multiple sections and delete some of the sections before or after mail merge.

Shows how to add/remove sections in a document.

// Open the document.
Document doc = new Document(MyDir + "Section.AddRemove.doc");

// This shows what is in the document originally. The document has two sections.

// Delete the first section from the document

// Duplicate the last section and append the copy to the end of the document.
int lastSectionIdx = doc.Sections.Count - 1;
Section newSection = doc.Sections[lastSectionIdx].Clone();

// Check what the document contains after we changed it.
See Also