Click or drag to resize

SectionCollection Class

Represents a collection of Section elements.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentElementCollection
    SautinSoft.DocumentElementCollectionSection
      SautinSoft.DocumentSectionCollection

Namespace:  SautinSoft.Document
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.8.6.14 (3.8.6.14)
Syntax
public sealed class SectionCollection : ElementCollection<Section>

The SectionCollection type exposes the following members.

Properties
  NameDescription
Public propertyContent
Gets the ContentRange of this collection.
(Inherited from ElementCollection.)
Public propertyCount
Gets the number of elements contained in this collection.
(Inherited from ElementCollection.)
Public propertyItem
Gets or sets the element at the specified index.
(Inherited from ElementCollectionT.)
Public propertySupportedElementTypes
Gets a sequence of ElementTypes that can be contained in this collection.
(Inherited from ElementCollection.)
Top
Methods
  NameDescription
Public methodAdd (Inherited from ElementCollectionT.)
Public methodClear
Removes all elements from this collection.
(Inherited from ElementCollection.)
Public methodContains (Inherited from ElementCollectionT.)
Public methodCopyTo(T, Int32) (Inherited from ElementCollectionT.)
Public methodCopyTo(Element, Int32)
Copies the entire collection to an Array, starting at a particular Array index.
(Inherited from ElementCollection.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetEnumerator
Gets an enumerator that iterates through the collection.
(Inherited from ElementCollectionT.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIndexOf (Inherited from ElementCollectionT.)
Public methodInsert (Inherited from ElementCollectionT.)
Public methodRemove (Inherited from ElementCollectionT.)
Public methodCode exampleRemoveAt
Removes the element at the specified index.
(Inherited from ElementCollection.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate methodIListAdd
Adds an item to the IList.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIListContains
Determines whether the IList contains a specific value.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodICollectionCopyTo
Copies the elements of the ICollection to an Array, starting at a particular Array index.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIEnumerableGetEnumerator
Returns an enumerator that iterates through a collection.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIListIndexOf
Determines the index of a specific item in the IList.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIListInsert
Inserts an item to the IList at the specified index.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyIListIsFixedSize
Gets a value indicating whether the IList has a fixed size.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyIListIsReadOnly
Gets a value indicating whether the IList is read-only.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyICollectionTIsReadOnly (Inherited from ElementCollectionT.)
Explicit interface implementationPrivate propertyICollectionIsSynchronized
Gets a value indicating whether access to the ICollection is synchronized (thread safe).
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyIListItem
Gets or sets the element at the specified index.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIListRemove
Removes the first occurrence of a specific object from the IList.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate methodIListRemoveAt
Removes the IList item at the specified index.
(Inherited from ElementCollection.)
Explicit interface implementationPrivate propertyICollectionSyncRoot
Gets an object that can be used to synchronize access to the ICollection.
(Inherited from ElementCollection.)
Top
Examples
Creates a document with different sections using C#
using System;
using SautinSoft.Document;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            Sections();
        }

        /// <summary>
        /// Creates a document with different sections.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/sections-and-page-layout.php
        /// </remarks>
        static void Sections()
        {
            string documentPath = @"Sections.docx";

            // Let's create a simple document with two Sections.
            DocumentCore dc = new DocumentCore();

            // First Section, A4 - Portrait.
            Section s1 = new Section(dc);
            s1.PageSetup.PaperType = PaperType.A4;
            s1.PageSetup.Orientation = Orientation.Portrait;
            dc.Sections.Add(s1);

            // Add some text into section 1.
            s1.Content.Start.Insert("Text in section 1", new CharacterFormat() { FontName = "Times New Roman", Size = 60.0 });

            // Second Section, Letter - Landscape.
            Section s2 = new Section(dc);
            s2.PageSetup.PaperType = PaperType.Letter;
            s2.PageSetup.Orientation = Orientation.Landscape;
            dc.Sections.Add(s2);

            // Add some text into section 2.
            s2.Content.Start.Insert("Text in section 2", new CharacterFormat() { FontName = "Arial", Size = 72.0, FontColor = new Color("DD55AA") });

            // Save our document into DOCX format.
            dc.Save(documentPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
Creates a document with different sections using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        Sections()
    End Sub

    ''' <summary>
    ''' Creates a document with different sections.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/sections-and-page-layout.php
    ''' </remarks>
    Sub Sections()
        Dim documentPath As String = "Sections.docx"

        ' Let's create a simple document with two Sections.
        Dim dc As New DocumentCore()

        ' First Section, A4 - Portrait.
        Dim s1 As New Section(dc)
        s1.PageSetup.PaperType = PaperType.A4
        s1.PageSetup.Orientation = Orientation.Portrait
        dc.Sections.Add(s1)

        ' Add some text into section 1.
        s1.Content.Start.Insert("Text in section 1", New CharacterFormat() With {
                .FontName = "Times New Roman",
                .Size = 60.0
            })

        ' Second Section, Letter - Landscape.
        Dim s2 As New Section(dc)
        s2.PageSetup.PaperType = PaperType.Letter
        s2.PageSetup.Orientation = Orientation.Landscape
        dc.Sections.Add(s2)

        ' Add some text into section 2.
        s2.Content.Start.Insert("Text in section 2", New CharacterFormat() With {
                .FontName = "Arial",
                .Size = 72.0,
                .FontColor = New Color("DD55AA")
            })

        ' Save our document into DOCX format.
        dc.Save(documentPath)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
    End Sub
End Module
See Also