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.

Cloning

Document element instances in GemBox.Document can be only at one single location in a document at a time. To insert a document element into some other part of the same document, it must be cloned and the clone should be inserted.

Following example demonstrates how to clone document elements, first by cloning a section and its content, and then by individually cloning section content elements – blocks.

Screenshot
Cloning 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.IO;
using System.Linq;
using System.Text;
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");

        // Clone section
        document.Sections.Add(document.Sections[0].Clone(true));
        
        // Clone paragraphs
        foreach (Block item in document.Sections[0].Blocks)
            document.Sections.Last().Blocks.Add(item.Clone(true));

        document.Save("Cloning.docx");
    }
}
Imports System
Imports System.IO
Imports System.Linq
Imports System.Text
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")

        ' Clone section
        document.Sections.Add(document.Sections(0).Clone(True))

        ' Clone paragraphs
        For Each item As Block In document.Sections(0).Blocks
            document.Sections.Last().Blocks.Add(item.Clone(True))
        Next

        document.Save("Cloning.docx")

    End Sub

End Module

Check next sample.