Compare Two Word Documents for Differences
Compare two word documents for differences in C#
In a situation where you need to compare large size word files that are similar to each other, but have slight differences that you would like to know about.Therefore, finding these changes manually is quite a time-consuming process. GroupDocs.Comparison for .NET (which is a part of Conholdate.Total for .NET) provides you many options to compare a wide range of supported file formats.
After comparing the two Word files, you will get a resulting document in which the changes are highlighted in three different colors:
- Elements that were inserted in the first file. – blue, by default
- Elements wich were deleted from the first file – red, by default
- Elements that have changed their styles (font, color, etc.) – green, by default
Source / Target / Result Words files | |
---|---|
Source | ![]() |
Target | ![]() |
Result | ![]() |
Compare two word documents example
string sourcePath = @"source.doc"; // NOTE: Path to the source word document | |
string targetPath = @"target.doc"; // NOTE: Path to the target word document | |
string resultPath = @"result.doc"; // NOTE: Path to the result word document | |
using (Comparer comparer = new Comparer(sourcePath)) | |
{ | |
comparer.Add(targetPath); | |
CompareOptions compareOptions = new CompareOptions | |
{ | |
DetectStyleChanges = true, | |
DetalisationLevel = DetalisationLevel.High | |
}; | |
comparer.Compare(resultPath, compareOptions); | |
} |