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 System;
using GemBox.Document;

class Program
    static void Main()
        // If using 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 System
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using 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

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.

Like it?

Download Buy

If you want to try the GemBox.Document yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.