Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hello,

I can create and open Word document using C#. I am able to insert some new text, but now I am trying to insert track changes and comments on this document.

I've tried with some libraries but this was unsuccessful. Is anybody faced with this type of problem or know some libraries (free or commercial) who can help me in the finding solution of this problem.

Here is the code for creating and adding a text in a new Word document, on this document I want to add track changes, but I don't know how:

C#
public static void CreateDocument()
    {
        try
        {
            //Create an instance for word app
            Word.Application winword = new Word.Application();

            //Set animation status for word application
            winword.ShowAnimation = false;

            //Set status for word application is to be visible or not.
            winword.Visible = false;

            //Create a missing variable for missing value
            object missing = System.Reflection.Missing.Value;

            //Create a new document
            Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);

            //adding text to document
            document.Content.SetRange(0, 0);
            document.Content.Text = "In this text I should add track changes " + Environment.NewLine;

            //Allow track changes, but I don't know how to use now
            document.TrackRevisions = true;
           
            //Save the document
            object filename = @"c:\temp1.docx";
            document.SaveAs2(ref filename);
            document.Close(ref missing, ref missing, ref missing);
            document = null;
            winword.Quit(ref missing, ref missing, ref missing);
            winword = null;
        }
        catch (Exception ex)
        {
        }
    }


Thank you in advance!
Posted
Updated 5-Jul-15 11:55am
v2
Comments
Afzaal Ahmad Zeeshan 5-Jul-15 16:15pm    
You would find the code to do so in the same Interop assembly that you are using right now. :)

What code are you using? If you could add that code, it would help experts to guide you. :)
zlristovski 5-Jul-15 17:56pm    
I improve my question and added some code. Thanks for the advice!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900