DocumentClone Method

Performs a deep copy of the Document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.10.0

ExpandedSyntax

public Document Clone()

Return Value

Type: Document
The cloned document.

ExpandedExamples

Shows how to deep clone a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Hello world!");

// Cloning will produce a new document with the same contents as the original,
// but with a unique copy of each of the original document's nodes.
Document clone = doc.Clone();

Assert.AreEqual(doc.FirstSection.Body.FirstParagraph.Runs[0].GetText(), 
    clone.FirstSection.Body.FirstParagraph.Runs[0].Text);
Assert.AreNotEqual(doc.FirstSection.Body.FirstParagraph.Runs[0].GetHashCode(),
    clone.FirstSection.Body.FirstParagraph.Runs[0].GetHashCode());

ExpandedSee Also