How to compare two Microsoft Word DOCX Files in C# .NET Framework

Comparing DOCX files is a complex problem, and not one with any simple solution if you are trying to create a manual solution yourself. Generally speaking, this format is difficult to parse, and even more difficult to create a means of comparison, when there are so many different elements that could come into play. In order for us to get this done before tea time, we will be whipping out an API that will do all the work for us. Let’s begin.

First we install our client using this command for NuGet’s console:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8

Following that we can call our function using this example code here:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class CompareDocumentDocxExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new CompareDocumentApi();var inputFile1 = new System.IO.Stream(); // System.IO.Stream | First input file to perform the operation on.var inputFile2 = new System.IO.Stream(); // System.IO.Stream | Second input file to perform the operation on (more than 2 can be supplied).try{// Compare Two Word DOCXbyte[] result = apiInstance.CompareDocumentDocx(inputFile1, inputFile2);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling CompareDocumentApi.CompareDocumentDocx: " + e.Message );}}}}

Done!

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store