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)

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        // Delete paragraph break between 1st and 2nd paragraph (concatenate 1st and 2nd paragraph)
17        var blocks = document.Sections[0].Blocks;
18        var paragraphBreakRange = new ContentRange(blocks[0].Content.End, blocks[1].Content.Start);
19        paragraphBreakRange.Delete();
20
21        // Delete content of 2nd run
22        blocks.Cast<Paragraph>(0).Inlines[1].Content.Delete();
23
24        document.Save("Delete Content.docx");
25    }
26}
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        ' Delete paragraph break between 1st and 2nd paragraph (concatenate 1st and 2nd paragraph)
16        Dim blocks = document.Sections(0).Blocks
17        Dim paragraphBreakRange = New ContentRange(blocks(0).Content.End, blocks(1).Content.Start)
18        paragraphBreakRange.Delete()
19
20        ' Delete content of 2nd run
21        blocks.Cast(Of Paragraph)(0).Inlines(1).Content.Delete()
22
23        document.Save("Delete Content.docx")
24
25    End Sub
26
27End Module

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