Get Content in Word Files Using C# and VB.NET

GemBox.Document allows you to get content in Word files programmatically in your C# and VB.NET applications.

The content of a document is represented with the ContentRange class which is exposed to the following members:

The following example shows how you can retrieve the plain text representation of document elements by using the ContentRange.ToString method.

Document elements plain text representation
Screenshot of retrieved document elements text
Upload your file (Drag file here)
using GemBox.Document;
using System;

class Program
    static void Main()
        // If using the Professional version, put your serial key below.

        var document = DocumentModel.Load("%InputFileName%");

        // Get content from each paragraph.
        foreach (Paragraph paragraph in document.GetChildElements(true, ElementType.Paragraph))
            Console.WriteLine($"Paragraph: {paragraph.Content.ToString()}");

        // Get content from each bold run.
        foreach (Run run in document.GetChildElements(true, ElementType.Run))
            if (run.CharacterFormat.Bold)
                Console.WriteLine($"Bold run: {run.Content.ToString()}");
Imports GemBox.Document
Imports System

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.

        Dim document As DocumentModel = DocumentModel.Load("%InputFileName%")

        ' Get content from each paragraph.
        For Each paragraph As Paragraph In document.GetChildElements(True, ElementType.Paragraph)
            Console.WriteLine($"Paragraph: {paragraph.Content.ToString()}")

        ' Get content from each bold run.
        For Each run As Run In document.GetChildElements(True, ElementType.Run)
            If run.CharacterFormat.Bold Then
                Console.WriteLine($"Bold run: {run.Content.ToString()}")
            End If

    End Sub
End Module

See also

Next steps

GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API. How about testing it today?

Download Buy