Get Content

Content of a document is represented with ContentRange class which is exposed on following members:

Following example demonstrates how to retrieve plain text representation of document elements by using ContentRange.ToString() method on their content.

Screenshot

Get Content Screenshot

See the full code below, use RUN EXAMPLE to execute.

Upload your file (Drag files here)

1using System;
2using System.Text;
3using System.Linq;
4using GemBox.Document;
5
6class Sample
7{
8    [STAThread]
9    static void Main(string[] args)
10    {
11        // If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
13
14        DocumentModel document = DocumentModel.Load("Reading.docx");
15
16        var sb = new StringBuilder();
17
18        // Get content from each paragraph
19        foreach (Paragraph paragraph in document.GetChildElements(true, ElementType.Paragraph))
20        {
21            sb.AppendFormat("Paragraph: {0}", paragraph.Content.ToString());
22            sb.AppendLine();
23        }
24
25        // Get content from each bold run
26        foreach (Run run in document.GetChildElements(true, ElementType.Run))
27        {
28            if (run.CharacterFormat.Bold)
29            {
30                sb.AppendFormat("Bold run: {0}", run.Content.ToString());
31                sb.AppendLine();
32            }
33        }
34
35        Console.WriteLine(sb.ToString());
36    }
37}
1Imports System
2Imports System.Text
3Imports System.Linq
4Imports GemBox.Document
5
6Module Samples
7
8    Sub Main()
9
10        ' If using Professional version, put your serial key below.
11        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
12
13        Dim document As DocumentModel = DocumentModel.Load("Reading.docx")
14
15        Dim sb = New StringBuilder()
16
17        ' Get content from each paragraph
18        For Each paragraph As Paragraph In document.GetChildElements(True, ElementType.Paragraph)
19            sb.AppendFormat("Paragraph: {0}", paragraph.Content.ToString())
20            sb.AppendLine()
21        Next
22
23        ' Get content from each bold run
24        For Each run As Run In document.GetChildElements(True, ElementType.Run)
25            If (run.CharacterFormat.Bold) Then
26                sb.AppendFormat("Bold run: {0}", run.Content.ToString())
27                sb.AppendLine()
28            End If
29        Next
30
31        Console.WriteLine(sb.ToString())
32
33    End Sub
34
35End Module

Check next sample or find out more about GemBox.Document and GemBox Software.