We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Code to extract more information out of MS Word document comparison .Net

Hi,

I have got an automated task in hand to compare same documents coming from different source to find out differences.
So far I am able to figure out the comparison code as per following but my management wants more details about each revision about the changes for example what color, style, margins, shapes, shapetypes, tables or any formatting were changed.

Do you have something handy or help me to extract as much as possible information out of it?
I preparing a visual tool with differences.

public int CompareDocs(string doc1Name, string doc2Name)
{
Aspose.Words.Document document1 = new Aspose.Words.Document(_DirectoryPath + doc1Name);
Aspose.Words.Document document2 = new Aspose.Words.Document(_DirectoryPath + doc2Name);

        document1.Compare(document2, "VarunA", DateTime.Now);

        string comparison = string.Empty;
        int count = 0;
        foreach(Revision revision in document1.Revisions)
        {
            count++;
            comparison += $" Comparison { count.ToString() }. Revision Type: { revision.RevisionType.ToString() }";
            if (revision.RevisionType != RevisionType.StyleDefinitionChange)
            {
                comparison += $" on a node of type : {revision.ParentNode.NodeType.ToString()}, ";
                if(revision.ParentNode.NodeType == NodeType.Shape)
                {
                    comparison += $" shape type : {(revision.ParentNode as Aspose.Words.Drawing.Shape).ShapeType.ToString()}, ";
                }
                
                comparison += $"Changed Text: {revision.ParentNode.GetText() }\n";
            }
            else
            {
                comparison += $" on a style : {revision.ParentStyle.Name} \n";
            }
            
        }
        log.Info(comparison);
        return count;

}

@varun.arora

Your are getting the revisions detail correctly. You may get the detail of revision group as shown below.

Document doc = new Document(MyDir + "Revisions.docx");

foreach (RevisionGroup group in doc.Revisions.Groups)
{
    Console.WriteLine(
        $"Revision author: {group.Author}; Revision type: {group.RevisionType} \n\tRevision text: {group.Text}");
}

We suggest you please read the following article.

Moreover, we suggest you please read the members of RevisionCollection class.

If you still face problem, please share some more detail about your requirement along with input document and expected output. We will then provide you more information on it.