Accept or Reject revisions

GroupDocs.Comparison allows you to get revisions from a Docx file format, process, and save the processing result. To take revisions from a document,_accept / reject revisions, and write the processing result to the output file, follow these steps:

  1. Instantiate the RevisionHandler object. Specify the source document path or stream.
  2. Call the GetRevisions method to get the revision list.
  3. Set the Action property of the object to be changed to the RevisionAction.Accept or RevisionAction.Reject value.
  4. Call the ApplyRevisionChanges method. Specify the created instance of the ApplyRevisionOptions class and path or stream of the output document, collecting changes in the revisions.

You can process all changes together within one action.To handle all changes at once, follow these steps:

  1. Instantiate the RevisionHandler object. Specify the source document path or stream.
  2. Call the ApplyRevisionChanges method. Specify the ApplyRevisionOptions object and one of the (RevisionAction.Accept, RevisionAction.Reject or RevisionAction.None) values.

The main properties of the ApplyRevisionOptions class are as follows:

  • Changes is a list of revision changes that need to be applied to the final document
  • CommonHandler allows you to define one action to handle all revision

If you do not specify the path or file to the output document for the ApplyRevisionChanges method, the source file is rewritten.

The following code snippets show how to get revisions from a document, accept / reject detected revisions and save changes to the output document:

Accept or Reject revisions from local disk

using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
using System.Collections.Generic;
using GroupDocs.Comparison.Words.Revision;
// ...

using (RevisionHandler revisionHandler = new RevisionHandler(
    pathRevision + "Document_with_revision.docx"))
{
    List<RevisionInfo> revisionList = revisionHandler.GetRevisions();
    foreach (RevisionInfo revision in revisionList)
    {
        if (revision.Type == RevisionType.Insertion) revision.Action = RevisionAction.Accept;
    }
    revisionHandler.ApplyRevisionChanges(pathRevision + "result.docx", new ApplyRevisionOptions() 
    { 
        Changes = revisionList 
    });
}

Accept or Reject revisions from stream

using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
using System.Collections.Generic;
using GroupDocs.Comparison.Words.Revision;
// ...

using (RevisionHandler revisionHandler = new RevisionHandler(
    File.OpenRead("Document_with_revision.docx")))
{
    List<RevisionInfo> revisionList = revisionHandler.GetRevisions();
    foreach (RevisionInfo revision in revisionList)
    {
        if (revision.Type == RevisionType.Insertion) revision.Action = RevisionAction.Accept;
    }
    revisionHandler.ApplyRevisionChanges(pathRevision + "result.docx", new ApplyRevisionOptions() 
    { 
        Changes = revisionList 
    });
}

Accept or Reject all revisions

using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
using System.Collections.Generic;
using GroupDocs.Comparison.Words.Revision;
// ...

using (RevisionHandler revisionHandler = new RevisionHandler(
    pathRevision + "Document_with_revision.docx"))
{
    revisionHandler.ApplyRevisionChanges(pathRevision + "result.docx", new ApplyRevisionOptions() 
    { 
        CommonHandler = RevisionAction.Accept 
    });
}

Result of revision processing

Below are the source and output files based on the code presented earlier.

Source fileResult file