GroupDocs.Comparison for .NET Library – Compare Two Word Documents in C# / ASP.NET

GroupDocs.Comparison for .NET Logo

Need to merge / compare two Word documents in .NET (C#, VB.NET)? GroupDocs.Comparison is the solution you might be looking for. It is a lightweight .NET library for generating diffs between two versions of a document. The library merges documents, compares their contents and styles, provides you with a complete list of changes found and also generates a diff view through a convenient web UI.

The UI can be easily integrated in any ASP.NET project, including MVC and WebForms. Merged documents are displayed through the UI with the diff view approach similar to Microsoft Word’s change tracking feature. End users can view compared documents from any modern browser without having to install any plugins or 3rd party software.

If your application does not produce a UI, you can simply use the ComparisonService to process documents in the console or a desktop app.

Supported File Formats

The library allows you to merge / compare up to 3 Word documents. You can compare DOC vs DOC, DOCX vs DOCX and DOC vs DOCX. In addition to that, the library allows you to compare two PDF, Excel (XLS, XLSX), PowerPoint (PPT, PPTX), plain text (TXT), OpenDocument (ODT) or HTML files.

Compare Text & Formatting

The library recognizes changes in text, tables, headers, footers, footnotes and even styles formatting. The last option is currently available only for Microsoft Word documents and recognizes changes in font type, size and style, such as bold, italic, underline, strike-through, etc.

Style changes detected with GroupDocs.Comparison for .Net

Compare 3 Versions of a Word Document

In console mode, GroupDocs.Comparison can compare up to 3 Word documents at once. To enable the feature, use the following code in place of the TargetFileName method of the ComparisonService instance:

service.Merge(new[] { new RevisedWordDocument(@"..\..\AppData\Tables.Edit1.docx", "Editor 1"),
                      new RevisedWordDocument(@"..\..\AppData\Tables.Edit2.docx", "Editor 2") });


Let’s now take a quick look at two simple scenarios of how the library can be used. As I already mentioned, the library can work both in conjunction with the diff view web UI and in a desktop environment.

Displaying Diffs through the User Interface

Assume we have an MVC application. There are few things that have to be configured to deploy the library. First, in the Application_Start of your Global.asax, you need to set the base and license paths. Also, please remember to initialize GroupDocs.Comparison:


Once this is done, on the view template you will be able to launch document comparison with the following lines of code:

@using Groupdocs.Web.UI.Comparison

<div id="comparison-wrapper"></div>


This code is for the Razor template engine. Also, please don’t forget to include JavaScript and CSS resources on the page.


Comparing Documents in a Desktop Environment

To process files in a desktop application you have to follow the same pattern: first, configure and initialize the library then launch the document comparison mechanism:


Basically, all comparison operations in the console version are the same as in the UI one. The Compare method returns a set of found changes that you may then process yourself. One thing that is different in the UI scenario from the console one is that all document processing operations are performed through the ComparisonService instance:

var service = new ComparisonService();


For more details on the library and to download a free evaluation copy, please visit the product’s homepage. We also prepared documentation and project samples to help you get started quickly. Feel free to contact us for any deployment assistance or feature requests.