Accept or Reject detected changes
Leave feedback
On this page
GroupDocs.Comparison allows you to apply or discard specific changes between source and target documents and save output document with (or without) selected changes.
To apply/reject changes to output document, follow these steps:
- Instantiate the Comparer object. Specify the source document path or stream.
- Call the Add method. Specify the target document path or stream.
- Call the Compare method.
- Call the GetChanges method to get changes list.
- Set the ComparisonAction of the appropriate change object to the ComparisonAction.Accept or ComparisonAction.Reject value.
- Call the ApplyChanges method. Specify the collection of changes.
ApplyChangeOptions class includes the following properties:
- Changes is a list of changes that must be applied (or not) to the output document
- SaveOriginalState is an option to reep the original state of the compared result after applying changes
The following code snippets show how to accept/reject changes:
using (Comparer comparer = new Comparer("source.docx"))
{
comparer.Add("target.docx");
comparer.Compare();
ChangeInfo[] changes = comparer.GetChanges();
changes[0].ComparisonAction = ComparisonAction.Reject;
comparer.ApplyChanges(File.Create("result.docx"), new SaveOptions(), new ApplyChangeOptions() { Changes = changes });
}
The result is as follows:
Accepted changes | Rejected changes |
---|---|
using (Comparer comparer = new Comparer(File.OpenRead("source.docx")))
{
comparer.Add(File.OpenRead("target.docx"));
comparer.Compare(new SaveOptions(), new CompareOptions());
ChangeInfo[] changes = comparer.GetChanges(new GetChangeOptions());
changes[0].ComparisonAction = ComparisonAction.Reject;
comparer.ApplyChanges(File.Create("result.docx"), new SaveOptions(), new ApplyChangeOptions() { Changes = changes });
}
using (Comparer comparer = new Comparer("source.docx"))
{
comparer.Add("target.docx");
comparer.Compare();
ChangeInfo[] changes = comparer.GetChanges();
changes[0].ComparisonAction = ComparisonAction.Reject;
comparer.ApplyChanges("resultWithRejectedChange.docx", new ApplyChangeOptions() { Changes = changes, SaveOriginalState = true });
changes = comparer.GetChanges();
changes[0].ComparisonAction = ComparisonAction.Accept;
comparer.ApplyChanges("resultWithAcceptedChange.docx", new ApplyChangeOptions() { Changes = changes });
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.