Get source and target text from files
Leave feedback
On this page
GroupDocs.Comparison allows you to get source and target texts of specific changes in the output file.
To get a list of changed source and target texts, 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.
The following code snippets show how to get specified texts from a file.
using (Comparer comparer = new Comparer(sourceDocumentPath))
{
comparer.Add(targetDocumentPath);
comparer.Compare(outputPath);
ChangeInfo[] changes = comparer.GetChanges();
foreach (ChangeInfo change in changes)
{
Console.WriteLine("");
Console.WriteLine("Source text: " + change.SourceText);
Console.WriteLine("Target text: " + change.TargetText);
}
}
The result is as follows:
using (Comparer comparer = new Comparer(File.OpenRead("source.docx")))
{
comparer.Add(File.OpenRead("target.docx"));
comparer.Compare(outputPath);
ChangeInfo[] changes = comparer.GetChanges();
foreach (ChangeInfo change in changes)
{
Console.WriteLine("");
Console.WriteLine("Source text: " + change.SourceText);
Console.WriteLine("Target text: " + change.TargetText);
}
}
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.