Click or drag to resize

ContentRange Class

Represents an area in document bounded by two ContentPositions.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentContentRange

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.12.16
Syntax
public sealed class ContentRange

The ContentRange type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleContentRange Initializes a new instance of the ContentRange class.
Top
Properties
 NameDescription
Public propertyCode exampleEnd Gets the ContentPosition that marks the end of the current ContentRange.
Public propertyFormFieldsData Gets collection of FormFieldData instances from all form fields in the current range.
Public propertyCode exampleStart Gets the ContentPosition that marks the beginning of the current ContentRange.
Top
Methods
 NameDescription
Public methodCode exampleDelete Deletes the document content specified with the current ContentRange.
Public methodEquals Determines whether the specified object is equal to this ContentRange instance.
(Overrides ObjectEquals(Object))
Public methodCode exampleFind(Regex) Finds all ContentRanges which match the specified Regex.
Public methodCode exampleFind(String) Finds all ContentRanges which contain the specified text.
Public methodGetHashCode Serves as the default hash function.
(Overrides ObjectGetHashCode)
Public methodCode exampleReplace(ContentRange) Replaces the content of the current ContentRange's with a content specified with the range parameter.
Public methodCode exampleReplace(String) Replaces the current ContentRange's content with the specified text.
Public methodReplace(ContentRange, ImportSession) Replaces the content of the current ContentRange's with a content (from another DocumentCore instance) specified with the range parameter.
Public methodCode exampleReplace(String, CharacterFormat) Replaces the current ContentRange's content with the specified text with specific formatting.
Public methodCode exampleReplace(String, HtmlLoadOptions) Replaces the current ContentRange's content with the specified HTML text.
Public methodCode exampleReplace(String, RtfLoadOptions) Replaces the current ContentRange's content with the specified RTF text.
Public methodCode exampleReplace(String, TxtLoadOptions) Replaces the current ContentRange's content with the specified text.
Public methodCode exampleReplace(String, CharacterFormat, TxtLoadOptions) Replaces the current ContentRange's content with the specified text with specific formatting.
Public methodCode exampleToString Returns a plain text that represents this ContentRange instance.
(Overrides ObjectToString)
Top
Example

See Developer Guide: Adds two paragraphs by different ways: using ContentRange and as Element

Adds two paragraphs by different ways: using ContentRange and as Element in C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
using SautinSoft.Document.Tables;
using System.Linq;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 100-day key here:   
            // https://sautinsoft.com/start-for-free/

            ContentRangeManipulation();
        }
        /// <summary>
        /// Adds two paragraphs by different ways: using ContentRange and as Element.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/contentrange-manipulation.php
        /// </remarks>
        static void ContentRangeManipulation()
        {
            string filePath = @"Result.docx";

            // Let's create a new document.
            DocumentCore dc = new DocumentCore();

            // Way 1: Add new paragraph using the property Content (class ContentRange).
            Paragraph par = new Paragraph(dc, "This is paragraph. ");
            par.ParagraphFormat.BackgroundColor = Color.Yellow;
            // Note, our Paragraph will be cloned and the clone will be inserted. 
            // The property Content (class ContentRange) each time clones the inserting object.
            dc.Content.End.Insert(par.Content);

            // Way 2: Add paragraph into the Block collection as Element.
            // Note, you can't insert the one Element two times.
            // The cloning does not occur here.
            par.ParagraphFormat.BackgroundColor = Color.Red;
            dc.Sections[0].Blocks.Add(par);

            // Again Way 1: Change Background color to blue and insert 
            // the copy (clone) of our paragraph using Content (class ContentRange).
            par.ParagraphFormat.BackgroundColor = Color.Blue;
            dc.Content.End.Insert(par.Content);

            // Change background to 'Green' for the paragraph.
            // This affect only to the paragraph inserted by 'Way 2' - as Element.
            // Because in 'Way 1' we added clones using ContentRange.
            par.ParagraphFormat.BackgroundColor = Color.Green;

            // Save our document.
            dc.Save(filePath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
    }
}
Adds two paragraphs by different ways: using ContentRange and as Element in VB.Net
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing
Imports SautinSoft.Document.Tables
Imports System.Linq

Module Sample
    Sub Main()
        ContentRangeManipulation()
    End Sub
    ''' Get your free 100-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Adds two paragraphs by different ways: using ContentRange and as Element.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/contentrange-manipulation.php
    ''' </remarks>
    Sub ContentRangeManipulation()
        Dim filePath As String = "Result.docx"

        ' Let's create a new document.
        Dim dc As New DocumentCore()

        ' Way 1: Add new paragraph using the property Content (class ContentRange).
        Dim par As New Paragraph(dc, "This is paragraph. ")
        par.ParagraphFormat.BackgroundColor = Color.Yellow
        ' Note, our Paragraph will be cloned and the clone will be inserted. 
        ' The property Content (class ContentRange) each time clones the inserting object.
        dc.Content.End.Insert(par.Content)

        ' Way 2: Add paragraph into the Block collection as Element.
        ' Note, you can't insert the one Element two times.
        ' The cloning does not occur here.
        par.ParagraphFormat.BackgroundColor = Color.Red
        dc.Sections(0).Blocks.Add(par)

        ' Again Way 1: Change Background color to blue and insert 
        ' the copy (clone) of our paragraph using Content (class ContentRange).
        par.ParagraphFormat.BackgroundColor = Color.Blue
        dc.Content.End.Insert(par.Content)

        ' Change background to 'Green' for the paragraph.
        ' This affect only to the paragraph inserted by 'Way 2' - as Element.
        ' Because in 'Way 1' we added clones using ContentRange.
        par.ParagraphFormat.BackgroundColor = Color.Green

        ' Save our document.
        dc.Save(filePath)

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