Compare Two Word Documents in C#, VB.NET

Spire.Doc for .NET supports comparing two Word documents and find the difference between them. In this article, you will learn how to use Spire.Doc for .NET to compare two Word documents in C# and VB.NET.

The input Word documents:

Compare Two Word Documents in C#, VB.NET

C#
using Spire.Doc;

namespace CompareWordDocuments
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document doc1 = new Document();
            //Load the first Word document
            doc1.LoadFromFile("Doc1.docx");

            //Create a Document instance
            Document doc2 = new Document();
            //Load the second Word document
            doc2.LoadFromFile("Doc2.docx");

            //Compare the two Word documents
            doc1.Compare(doc2, "Shawn");

            //Save the result to file
            doc1.SaveToFile("Result.docx");
            doc1.Dispose();
        }
    }
}
VB.NET
Imports Spire.Doc

Namespace CompareWordDocuments
    Class Program
        Private Shared Sub Main(ByVal args As String())
            ‘Create a Document instance
            Dim doc1 As Document = New Document()
            ‘Load the first Word document
            doc1.LoadFromFile("Doc1.docx")

            ‘Create a Document instance
            Dim doc2 As Document = New Document()
            ‘Load the second Word document
            doc2.LoadFromFile("Doc2.docx")

            ‘Compare the two Word documents
            doc1.Compare(doc2, "Shawn")

            ‘Save the result to file
            doc1.SaveToFile("Result.docx")
            doc1.Dispose()
        End Sub
    End Class
End Namespace

Output:

Compare Two Word Documents in C#, VB.NET