Click or drag to resize

BlockCollection Class

Represents a collection of a Block derived elements.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentElementCollection
    SautinSoft.DocumentElementCollectionBlock
      SautinSoft.DocumentBlockCollection

Namespace:  SautinSoft.Document
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.7.4.3 (3.7.4.3)
Syntax
public sealed class BlockCollection : ElementCollection<Block>

The BlockCollection 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
Iterates through a document and count the amount of Paragraphs and Runs using C#
using System;
using SautinSoft.Document;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            ShowInlines();
        }
        /// <summary>
        /// Iterates through a document and count the amount of Paragraphs and Runs.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/elementcollection-iteration.php
        /// </remarks>
        static void ShowInlines()
        {
            string filePath = @"..\..\example.docx";
            DocumentCore dc = DocumentCore.Load(filePath);
            Console.WriteLine("This document contains from:");
            for (int sect = 0; sect < dc.Sections.Count; sect++)
            {
                Console.WriteLine("Section {0} contains from:", sect);
                int totalParagraphs = 0;
                Section section = dc.Sections[sect];
                for (int blocks = 0; blocks < section.Blocks.Count; blocks++)
                {
                    if (section.Blocks[blocks] is Paragraph)
                    {
                        totalParagraphs++;
                        Paragraph paragraph = section.Blocks[blocks] as Paragraph;
                        Console.Write("\t\t Paragraph {0} contains from: ", totalParagraphs);
                        int totalRuns = 0;
                        for (int i = 0; i < paragraph.Inlines.Count; i++)
                        {
                            if (paragraph.Inlines[i] is Run)
                                totalRuns++;
                        }
                        Console.WriteLine("{0} Run(s).", totalRuns);
                    }


                }
            }
            Console.ReadKey();
        }
    }
}
Iterates through a document and count the amount of Paragraphs and Runs using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        ShowInlines()
    End Sub

    ''' <summary>
    ''' Iterates through a document and count the amount of Paragraphs and Runs.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/elementcollection-iteration.php
    ''' </remarks>
    Sub ShowInlines()
        Dim filePath As String = "..\example.docx"
        Dim dc As DocumentCore = DocumentCore.Load(filePath)
        Console.WriteLine("This document contains from:")
        For sect As Integer = 0 To dc.Sections.Count - 1
            Console.WriteLine("Section {0} contains from:", sect)
            Dim totalParagraphs As Integer = 0
            Dim section As Section = dc.Sections(sect)
            For blocks As Integer = 0 To section.Blocks.Count - 1
                If TypeOf section.Blocks(blocks) Is Paragraph Then
                    totalParagraphs += 1
                    Dim paragraph As Paragraph = TryCast(section.Blocks(blocks), Paragraph)
                    Console.Write(vbTab & vbTab & " Paragraph {0} contains from: ", totalParagraphs)
                    Dim totalRuns As Integer = 0
                    For i As Integer = 0 To paragraph.Inlines.Count - 1
                        If TypeOf paragraph.Inlines(i) Is Run Then
                            totalRuns += 1
                        End If
                    Next i
                    Console.WriteLine("{0} Run(s).", totalRuns)
                    Console.ReadKey()
                End If
            Next blocks
        Next sect
    End Sub
End Module
See Also