Compare two DOCX using C#

Highly accurate C# diff checker to compare DOCX files and find differences between them

Our powerful C# SDK allows you to find the difference between DOCX documents and save the results to a convenient format for viewing. To verify our product capabilities, compare DOCX files using this C# library and see the differences.

View code snippet

Compare DOCX in C#

Our .NET SDK is designed to give you the most accurate result, even though comparison is a complex function itself.

Sometimes you need to be sure that the document in the DOCX format has not been changed, and if it has, you need to find out what the difference is. Just use our .NET diff tool to compare two DOCX files and find differences in whole words or single characters. Moreover, if only one character in a word has changed, this word will be marked as changed entirely.

Now you no longer need to spend time manually comparing DOCX documents, and you can quickly find even small changes and export such diffs to a document in a convenient format.

Try to compare DOCX documents

Check out how our solution to compare DOCX files using .NET SDK works. To achieve this, load the DOCX files you want to compare and select the export file format – it will be automatically loaded after comparing.

Note that you need to accept all revisions in compared documents before calling the comparison method, as shown in our example:

Upload the compared file
Run code
Upload the second file to compare
Select the target format from the list
using Aspose.Words.Cloud.Sdk;

var config = new Configuration 
{
    ClientId = "####-####-####-####-####", 
    ClientSecret = "##################" 
};
var wordsApi = new WordsApi(config);

var fileName1 = "Input1.docx";
var fileName2 = "Input2.docx";
var fileResult = "Output.docx";

//  Upload documents to cloud storage.
using var firstDocumentContent = File.OpenRead(fileName1);
var uploadFirstFileRequest = new UploadFileRequest(firstDocumentContent, fileName1);
await wordsApi.UploadFile(uploadFirstFileRequest);

using var secondDocumentContent = File.OpenRead(fileName2);
var uploadSecondFileRequest = new UploadFileRequest(secondDocumentContent, fileName2);
await wordsApi.UploadFile(uploadSecondFileRequest);

//  Compare documents in cloud.
var compareDataOptions = new CompareData()
{
    Author = "author",
    ComparingWithDocument = fileName2
};
var compareDocumentRequest = 
    new CompareDocumentRequest(fileName1, compareDataOptions, destFileName: fileResult);
await wordsApi.CompareDocument(compareDocumentRequest);

//  Download result document from cloud storage.
var downloadFileRequest = new DownloadFileRequest(fileResult);
var downloadFileResult = await wordsApi.DownloadFile(downloadFileRequest);
using (var fileStream = File.Create(fileResult))
{
    downloadFileResult.CopyTo(fileStream);
}
Run code
  
Copy C# code to the clipboard

How to Compare two text files

  1. Install Aspose.Words Cloud for .NET
  2. Add a library reference (import the library) to your C# project
  3. Load two DOCX documents to compare
  4. Call the CompareDocument() method to compare DOCX docs
  5. Download the result document from the cloud storage

C# library to use compare

Install 'Aspose.Words Cloud SDK for .NET' using NuGet package manager. Just run nuget install Aspose.Words-Cloud to automatically install and reference the corresponding assembly in your project. As an alternative, you can manually clone Aspose.Words Cloud SDK for .NET source code from GitHub and use it in your project. Please follow these Instructions to quickly get the necessary security credentials and access our REST API.

System Requirements

  • .NET Standard 2.0 or newer

Refer to the Repository Documentation to see more details.

Other supported file formats

You can perform compare operation for other file formats:

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.