The example below demonstrates how to update existing metadata properties using a combination of criteria. Please note that the UpdateProperties method checks the type of all properties before applying any changes. If a property satisfies the predicate but has a type different from the passed value it won’t be updated. The explicit type check in the example is performed since we use the existing value to filter metadata properties.
DateTimetoday=DateTime.Today;DateTimethreeDaysAgo=today.AddDays(-3);foreach(stringfileinDirectory.GetFiles(Constants.InputPath)){using(Metadatametadata=newMetadata(file)){if(metadata.FileFormat!=FileFormat.Unknown&&!metadata.GetDocumentInfo().IsEncrypted){Console.WriteLine();Console.WriteLine(file);// Update the file creation date/time if the existing value is older than 3 daysvaraffected=metadata.UpdateProperties(p=>p.Tags.Contains(Tags.Time.Created)&&p.Value.Type==MetadataPropertyType.DateTime&&p.Value.ToStruct<DateTime>()<threeDaysAgo,newPropertyValue(today));Console.WriteLine("Affected properties: {0}",affected);metadata.Save(Path.Combine(Constants.OutputPath,"output"+Path.GetExtension(file)));}}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full featured .NET library we provide simple, but powerful free Apps.
You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.
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.