Click or drag to resize

ContentRangeToString Method

Returns a plain text that represents this ContentRange instance.

Namespace:  SautinSoft.Document
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.8.6.28 (3.8.6.28)
Syntax
public override string ToString()

Return Value

Type: String
A plain text that represents this ContentRange instance.
Examples
How to get a content from a document using C#
using System;
using SautinSoft.Document;
using System.Text;

namespace Sample
{
    class Sample
    {

        static void Main(string[] args)
        {
            GetContent();
        }

        /// <summary>
        /// How to get a content from a document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/get-content-net-csharp-vb.php
        /// </remarks>
        public static void GetContent()
        {
            // Path to an input document.
            string documentPath = @"..\..\example.docx";

            DocumentCore dc = DocumentCore.Load(documentPath);

            StringBuilder sb = new StringBuilder();

            // Get content of each paragraph in the document.
            foreach (Paragraph par in dc.GetChildElements(true, ElementType.Paragraph))
            {
                // The property 'Content' returns the content as ContentRange.
                // Get content and append it into StringBuilder.
                sb.AppendFormat("Paragraph: {0}", par.Content.ToString());
                sb.AppendLine();
            }

            // Get content of each Run where the text color is Red.
            foreach (Run run in dc.GetChildElements(true, ElementType.Run))
            {
                if (run.CharacterFormat.FontColor == Color.Red)
                {
                    // The property 'Content' returns the content as ContentRange.
                    // Get content and append it into StringBuilder.
                    sb.AppendFormat("Red color: {0}", run.Content.ToString());
                    sb.AppendLine();
                }
            }
            Console.WriteLine(sb.ToString());
            Console.ReadKey();
        }
    }
}
How to get a content from a document using VB.Net
Imports System
Imports SautinSoft.Document
Imports System.Text

Module Sample
    Sub Main()
        GetContent()
    End Sub

    ''' <summary>
    ''' How to get a content from a document.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/get-content-net-csharp-vb.php
    ''' </remarks>
    Sub GetContent()
        ' Path to an input document.
        Dim documentPath As String = "..\example.docx"

        Dim dc As DocumentCore = DocumentCore.Load(documentPath)

        Dim sb As New StringBuilder()

        ' Get content of each paragraph in the document.
        For Each par As Paragraph In dc.GetChildElements(True, ElementType.Paragraph)
            ' The property 'Content' returns the content as ContentRange.
            ' Get content and append it into StringBuilder.
            sb.AppendFormat("Paragraph: {0}", par.Content.ToString())
            sb.AppendLine()
        Next par

        ' Get content of each Run where the text color is Red.
        For Each run As Run In dc.GetChildElements(True, ElementType.Run)
            If run.CharacterFormat.FontColor = Color.Red Then
                ' The property 'Content' returns the content as ContentRange.
                ' Get content and append it into StringBuilder.
                sb.AppendFormat("Red color: {0}", run.Content.ToString())
                sb.AppendLine()
            End If
        Next run
        Console.WriteLine(sb.ToString())
        Console.ReadKey()
    End Sub
End Module
See Also