Comparing

Сompare documents and track changes like insertions, deletions, and modifications using C#.

Wordize provides an easy and efficient way to compare two documents and highlight their differences. This feature is useful for tracking changes between document versions, whether for collaboration, version control, or content auditing.

With the Wordize Comparison for .NET, you can programmatically compare two documents and generate a document with the detected changes. The comparison results include insertions, deletions, and modifications, making it easy to review document differences.

How to Compare Documents

When comparing documents, differences between the second and first documents are displayed as revisions in the first document – each detected change will have its own revision.

The comparison functionality in Wordize is accessible through the Comparer class, which provides the Compare methods for comparing documents.

If you want to compare two documents, you will need Wordize Comparison for .NET and the mandatory Wordize Core for .NET module with corresponding licenses:

  • The mandatory Wordize Core for .NET module allows users to load and save documents in Microsoft Word format. Without purchasing this module, none of the other modules will work.
  • The Wordize Comparison for .NET module provides the functionality to compare documents.

If you want to compare in other formats, you need additional modules. For example, to compare two HTML documents, you also need the additional Wordize Web for .NET module.

Compare DOCX Files

As mentioned above, to compare documents in DOCX format, you will need the Wordize Core for .NET and Wordize Comparison for .NET modules.

The following code example shows how to compare two documents using the Compare(string, string, string, string, DateTime) method:

string firstDoc = MyDir + "Document1.docx";
string secondDoc = MyDir + "Document2.doc";

Comparer.Compare(firstDoc, secondDoc, ArtifactsDir + "CompareDocuments.1.docx", "Author", new DateTime());

The following code example shows how to compare two documents using the Compare(Stream, Stream, Stream, SaveFormat, string, DateTime) method:

using (FileStream firstStreamIn = new FileStream(MyDir + "Document1.docx", FileMode.Open, FileAccess.Read))
{
    using (FileStream secondStreamIn = new FileStream(MyDir + "Document2.docx", FileMode.Open, FileAccess.Read))
    {
        using (FileStream streamOut = new FileStream(ArtifactsDir + "CompareStreamDocuments.2.docx", FileMode.Create, FileAccess.ReadWrite))
            Comparer.Compare(firstStreamIn, secondStreamIn, streamOut, SaveFormat.Docx, "Author", new DateTime());
	}
}

The following code example shows how to compare two documents using the Compare(string, string, string, SaveFormat, string, DateTime) method:

string firstDoc = MyDir + "Document1.docx";
string secondDoc = MyDir + "Document2.doc";

Comparer.Compare(firstDoc, secondDoc, ArtifactsDir + "CompareDocuments.3.docx", SaveFormat.Docx, "Author", new DateTime());

The following code example shows how to compare two documents using the Compare(string, string, string, string, DateTime, CompareOptions) method:

string firstDoc = MyDir + "Document1.docx";
string secondDoc = MyDir + "Document2.doc";

CompareOptions compareOptions = new CompareOptions();
compareOptions.IgnoreCaseChanges =true;

Comparer.Compare(firstDoc, secondDoc, ArtifactsDir + "CompareDocuments.4.docx", "Author", new DateTime(), compareOptions);

The following code example shows how to compare two documents using the Compare(Stream, Stream, Stream, SaveFormat, string, DateTime, CompareOptions) method:

using (FileStream firstStreamIn = new FileStream(MyDir + "Document1.docx", FileMode.Open, FileAccess.Read))
{
    using (FileStream secondStreamIn = new FileStream(MyDir + "Document2.docx", FileMode.Open, FileAccess.Read))
    {
        using (FileStream streamOut = new FileStream(ArtifactsDir + "CompareStreamDocuments.5.docx", FileMode.Create, FileAccess.ReadWrite))
        {
            CompareOptions compareOptions = new CompareOptions();
            compareOptions.IgnoreCaseChanges = true;
            Comparer.Compare(firstStreamIn, secondStreamIn, streamOut, SaveFormat.Docx, "Author", new DateTime(), compareOptions);
        }
    }
}

The following code example shows how to compare two documents using the Compare(string, string, string, SaveFormat, string, DateTime, CompareOptions) method:

string firstDoc = MyDir + "Document1.docx";
string secondDoc = MyDir + "Document2.doc";

CompareOptions compareOptions = new CompareOptions();
compareOptions.IgnoreCaseChanges =true;

Comparer.Compare(firstDoc, secondDoc, ArtifactsDir + "LowCode.CompareDocuments.6.docx", SaveFormat.Docx, "Author", new DateTime(), compareOptions);