AddProperties

Metadata.AddProperties method

Adds known metadata properties satisfying the specified predicate. The operation is recursive so it affects all nested packages as well.

public int AddProperties(Func<MetadataProperty, bool> predicate, PropertyValue value)
Parameter Type Description
predicate Func`2 A function to test each metadata property for a condition.
value PropertyValue A value for the picked properties.

Return Value

The number of affected properties.

Remarks

Learn more

Examples

This example demonstrates how to add some missing metadata properties to a file regardless of its format.

using (Metadata metadata = new Metadata(Constants.InputDocx))
{
    // Add a property containing the file last printing date if it's missing
    // Note that the property will be added to metadata packages that satisfy the following criteria:
    // 1) Only existing metadata packages will be affected. No new packages are added during this operation
    // 2) There should be a known metadata property in the package structure that fits the search condition but is actually missing in the package.
    // All properties supported by a certain package are usually defined in the specification of a particular metadata standard
    var affected = metadata.AddProperties(p => p.Tags.Contains(Tags.Time.Printed), new PropertyValue(DateTime.Now));

    Console.WriteLine("Affected properties: {0}", affected);

    metadata.Save(Constants.OutputDocx);
}

See Also