Accept or Reject revisions
GroupDocs.Comparison provides the ability to get revisions from a Docx file format, process and save the processing result. Below are the steps to take revisions from a document, accept / reject revisions, and write the processing result to a final file.
- Instantiate RevisionHandler object with source document path or stream;
- Call GetRevisions method and obtain detected revision list;
- Set Action of needed change object to RevisionAction.Accept or RevisionAction.Reject value;
- Call the ApplyRevisionChanges method, to which you need to pass the newly created instance of the ApplyRevisionOptions object and pass to it path or stream of the resulting document, collecting changes in the revisions.
It is also possible to process all changes together, applying one action for all changes. Below are the steps to handle all changes:
- Instantiate RevisionHandler object with source document path or stream;
- Call the ApplyRevisionChanges method, to which you need to pass the newly created instance of the ApplyRevisionOptions object and pass to it action (RevisionAction.Accept, RevisionAction.Reject or RevisionAction.None) that will apply to all revisions.
ApplyRevisionOptions class:
- Changes - List of revision changes that need to be applied to the final document.
- CommonHandler - Property that allows you to define one action to handle all revision.
If you do not pass the path or file to the resulting document to the ApplyRevisionChanges method, the changes will be written to the same file from which the revisions were taken.
The following code example demonstrates how to get revisions from a document, accept / reject detected revisions and save changes to the resulting document.
Accept or Reject revisions from local disk
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 (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 (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 file | Result file |
---|---|
![]() | ![]() |
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Comparison for .NET examples, plugins, and showcase
- GroupDocs.Comparison for Java examples, plugins, and showcase
- Document Comparison for .NET MVC UI Example
- Document Comparison for .NET App WebForms UI Modern Example
- Document Comparison for Java App Dropwizard UI Modern Example
- Document Comparison for Java Spring UI Example
Free Online App
Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSG and other documents with free to use online GroupDocs Comparison App.