Check if two documents are same
Atir Tahir
Posted on September 17, 2020
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:
- Difference count
- Difference summary
- 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.
💖 💪 🙅 🚩
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.