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.

Delete Content

Following example shows how to delete part of document content with GemBox.Document component.

Screenshot
Delete Content Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download a sample file

using System;
using System.Text;
using System.Linq;
using GemBox.Document;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("Reading.docx");

        // Delete paragraph break between 1st and 2nd paragraph (concatenate 1st and 2nd paragraph)
        var blocks = document.Sections[0].Blocks;
        var paragraphBreakRange = new ContentRange(blocks[0].Content.End, blocks[1].Content.Start);
        paragraphBreakRange.Delete();

        // Delete content of 2nd run
        blocks.Cast<Paragraph>(0).Inlines[1].Content.Delete();

        document.Save("Delete Content.docx");
    }
}
Imports System
Imports System.Text
Imports System.Linq
Imports GemBox.Document

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("Reading.docx")

        ' Delete paragraph break between 1st and 2nd paragraph (concatenate 1st and 2nd paragraph)
        Dim blocks = document.Sections(0).Blocks
        Dim paragraphBreakRange = New ContentRange(blocks(0).Content.End, blocks(1).Content.Start)
        paragraphBreakRange.Delete()

        ' Delete content of 2nd run
        blocks.Cast(Of Paragraph)(0).Inlines(1).Content.Delete()

        document.Save("Delete Content.docx")

    End Sub

End Module

Check next sample.