Set document metadata on save
Usually documents can contain some metadata information, such as author, organization, etc. GroupDocs.Comparison provides an ability to select metadata source when saving resultant document.
Possible metadata sources are:
- Source document metadata;
- Target document metadata;
- User-defined metadata.
The following are the steps to set resultant document metadata.
- Instantiate Comparer object with source document path or stream;
- Call Add method and specify target document path or stream;
- Instantiate SaveOptions object and set CloneMetadataType property with desired MetadataType variant;
- Call Compare method and pass SaveOptions object to method.
The following code demonstrates how to set resultant document metadata.
Set metadata from source file
using (Comparer comparer = new Comparer("source.docx"))
{
comparer.Add("target.docx");
comparer.Compare("result.docx", new SaveOptions() { CloneMetadataType = MetadataType.Source });
}
Set metadata from target file
using (Comparer comparer = new Comparer("source.docx"))
{
comparer.Add("target.docx");
comparer.Compare("result.docx", new SaveOptions() { CloneMetadataType = MetadataType.Target });
}
Set user-defined metadata
using (Comparer comparer = new Comparer("source.docx"))
{
comparer.Add("target.docx");
SaveOptions saveOptions = new SaveOptions()
{
CloneMetadataType = MetadataType.FileAuthor,
FileAuthorMetadata = new FileAuthorMetadata
{
Author = "Tom",
Company = "GroupDocs",
LastSaveBy = "Jack"
}
};
comparer.Compare("result.docx", saveOptions);
}
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.