loading...
Cover image for Check if two documents are same

Check if two documents are same

atir_tahir profile image Atir Tahir ・1 min read

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();
}

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();
}

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.

Posted on by:

atir_tahir profile

Atir Tahir

@atir_tahir

Software developer and evangelist.

Discussion

pic
Editor guide