Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created November 27, 2019 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/b02f66ab5a9408f72b920cf030ce064a to your computer and use it in GitHub Desktop.
Save GroupDocsGists/b02f66ab5a9408f72b920cf030ce064a to your computer and use it in GitHub Desktop.
Regex pattern = new Regex("author|company", RegexOptions.IgnoreCase);
using (Metadata metadata = new Metadata(@"D:\input.docx"))
{
// This method searches for properties across all metadata packages and works with all supported formats
var properties = metadata.FindProperties(p => pattern.IsMatch(p.Name) || pattern.IsMatch(p.Value.ToString()));
foreach (var property in properties)
{
Console.WriteLine("{0} = {1}", property.Name, property.Value);
}
}
Regex pattern = new Regex("author|company", RegexOptions.IgnoreCase);
// This method works with document formats only
MetadataPropertyCollection properties = SearchFacade.ScanDocument(@"D:\input.docx", pattern);
for (int i = 0; i < properties.Count; i++)
{
Console.WriteLine(properties[i]);
}
var pattern = new Regex("^author|company$", RegexOptions.IgnoreCase);
var replaceValue = new PropertyValue("Aspose");
using (Metadata metadata = new Metadata(@"D:\input.docx"))
{
// This method updates writable properties across all metadata packages and works with all supported formats
metadata.UpdateProperties(p => pattern.IsMatch(p.Name), replaceValue);
metadata.Save(@"D:\output.docx");
}
Regex pattern = new Regex("^author|company$", RegexOptions.IgnoreCase);
string replaceValue = "Aspose";
// This method works with document formats only
SearchFacade.ReplaceInDocument(@"D:\input.docx", pattern, replaceValue, @"D:\output.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment