DocumentCompare(Document, String, DateTime) Method

Compares this document with another document producing changes as number of edit and format revisions Revision.

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

ExpandedSyntax

public void Compare(
	Document document,
	string author,
	DateTime dateTime
)

Parameters

document
Type: Aspose.WordsDocument
Document to compare.
author
Type: SystemString
Initials of the author to use for revisions.
dateTime
Type: SystemDateTime
The date and time to use for revisions.

ExpandedRemarks

The following document nodes are not compared at the moment:
Note Note
Documents must not have revisions before comparison.

ExpandedExamples

Shows how to compare documents.
Document docOriginal = new Document();
DocumentBuilder builder = new DocumentBuilder(docOriginal);
builder.Writeln("This is the original document.");

Document docEdited = new Document();
builder = new DocumentBuilder(docEdited);
builder.Writeln("This is the edited document.");

// Comparing documents with revisions will throw an exception.
if (docOriginal.Revisions.Count == 0 && docEdited.Revisions.Count == 0)
    docOriginal.Compare(docEdited, "authorName", DateTime.Now);

// After the comparison, the original document will gain a new revision
// for every element that's different in the edited document.
foreach (Revision r in docOriginal.Revisions)
{
    Console.WriteLine($"Revision type: {r.RevisionType}, on a node of type \"{r.ParentNode.NodeType}\"");
    Console.WriteLine($"\tChanged text: \"{r.ParentNode.GetText()}\"");
}

// Accepting these revisions will transform the original document into the edited document.
docOriginal.Revisions.AcceptAll();

Assert.AreEqual(docOriginal.GetText(), docEdited.GetText());

ExpandedSee Also