Check if two documents are same

atir_tahir

Atir Tahir

Posted on September 17, 2020

Check if two documents are same

In order to check whether two documents are same or not, you gotta do a detailed comparison. I will tell you about a document comparison API that returns a list of differences programmatically in C#.

Implementation

It won't take more than 4-5 lines of code to find out:

  1. Difference count
  2. Difference summary
  3. Inserted/deleted items or even a style change
using (Comparer comparer = new Comparer(@"D:/source.docx"))
{
        comparer.Add(@"D:/target.docx");
        comparer.Compare(@"D:/result.docx");
        ChangeInfo[] changes = comparer.GetChanges();
}
Enter fullscreen mode Exit fullscreen mode

You can even compare or get a list of changes from stream:

using (Comparer comparer = new Comparer(File.OpenRead("source.docx")))
{
        comparer.Add(File.OpenRead("target.docx));
        comparer.Compare("save resultant file");
        ChangeInfo[] changes = comparer.GetChanges();
}
Enter fullscreen mode Exit fullscreen mode

You can compare PDF, Excel, Presentation or any other supported files. All you have to do is to download this DLL and add it as a reference in your .NET project (existing or new). Post your issues here to get free support.

💖 💪 🙅 🚩
atir_tahir
Atir Tahir

Posted on September 17, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Check if two documents are same
dotnet Check if two documents are same

September 17, 2020