How to accept/reject the tracked changes on word document in C#

When we operate the word documents by edit the wording, and its format on the word documents, we usually use Microsoft Word's Tracking Changes feature to mark our every changes. Later if we want to share the final version of our document to others, we need to remove the tracked changes by accepting them or rejecting them. Spire.Doc offers a property Document.TrackChanges to turn on/off track changes and the method of Document.AcceptChanges();/Document.RejectChanges(); to accept/reject the track changes. This article will show you how to accept/reject the tracked changes on word document in C# with the help of Spire.Doc.

Firstly view the sample word document with tracked changes:

How to accept/reject the tracked changes on word document in C#

Here comes to the steps of how to accept or reject the tracked changes:

Step 1: Create a new word document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("sample.docx");

Step 2: Get the first section and the paragraph we want to accept/reject the changes.

Section sec = doc.Sections[0];
Paragraph para = sec.Paragraphs[0];

Step 3: Accept the changes or reject the changes.

para.Document.AcceptChanges();
//para.Document.RejectChanges();

Step 4: Save the document to file.

doc.SaveToFile("result.docx", FileFormat.Docx);

Effective screenshot after accept the tracked changes:

How to accept/reject the tracked changes on word document in C#

Full codes:

static void Main(string[] args)
{
    Document doc = new Document();
    doc.LoadFromFile("sample.docx");

    Section sec = doc.Sections[0];
    Paragraph para = sec.Paragraphs[0];

    para.Document.AcceptChanges();

//para.Document.RejectChanges();

 doc.SaveToFile("result.docx", FileFormat.Docx);

}