DEV Community

Cover image for Check if two documents are same
Atir Tahir
Atir Tahir

Posted on

2 3

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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
sabarishcodes profile image
Sabarish Rajamohan

Cool stuff! 😍

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay