Search code examples
c#comoffice-interop

How to determine whether two word documents are the same using word interop


Is there a good way to see if two documents are the same using the word interop?

I have tried using something like:

Word.Document tempDoc = app.CompareDocuments(document1, document2);

My issue is that tempDoc is not null if they are the same, so I'm not sure how to use this result to determine whether the documents are the same.

Thanks in advance!


Solution

  • The document it returns is a document with track changes turned on. So all you have to do is see if there ARE any changes. So:

    Document tempDoc = app.CompareDocuments(doc1, doc2);
    bool anyChanges = tempDoc.Revisions.Count > 0;
    

    See:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._application.comparedocuments.aspx