Delete Content

You can remove any element from the document by removing it from the parent element. This can be done by using the ElementCollection.RemoveAt method on the Element.ParentCollection. collection.

You can also delete any arbitrary document content like parts of an element, as well as single or multiple elements. This is done by using the ContentRange.Delete method.

The following example shows how you can delete different parts of the document.

Deleted elements and specific text from Word file.
Screenshot of deleted content in output Word document
using System.Linq;
using GemBox.Document;

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

        var document = DocumentModel.Load("%#Reading.docx%");

        // Delete 1st paragraph's inlines.
        var paragraph1 = document.Sections[0].Blocks.Cast<Paragraph>(0);

        // Delete 3rd and 4th run from the 2nd paragraph.
        var paragraph2 = document.Sections[0].Blocks.Cast<Paragraph>(1);
        var runsContent = new ContentRange(

        // Delete specified text content.
        var bracketContent = document.Content.Find("(").First();

        document.Save("Delete Content.%OutputFileType%");
Imports System.Linq
Imports GemBox.Document

Module Program

    Sub Main()

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

        Dim document = DocumentModel.Load("%#Reading.docx%")

        ' Delete 1st paragraph's inlines.
        Dim paragraph1 = document.Sections(0).Blocks.Cast(Of Paragraph)(0)

        ' Delete 3rd and 4th run from the 2nd paragraph.
        Dim paragraph2 = document.Sections(0).Blocks.Cast(Of Paragraph)(1)
        Dim runsContent = New ContentRange(

        ' Delete specified text content.
        Dim bracketContent = document.Content.Find("(").First()

        document.Save("Delete Content.%OutputFileType%")

    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