using(Metadatametadata=newMetadata(Constants.InputDocx)){// Fetch all metadata properties from the filevarproperties=metadata.FindProperties(p=>true);foreach(varpropertyinproperties){// Process string and DateTime properties onlyif(property.Value.Type==MetadataPropertyType.String){Console.Write(property.Value.ToClass<string>());}elseif(property.Value.Type==MetadataPropertyType.DateTime){Console.Write(property.Value.ToStruct(DateTime.MinValue));}}}
But if it’s necessary to process all supported types of values you may find the alternative way more convenient.
staticvoidMain(string[]args){using(Metadatametadata=newMetadata(Constants.InputDocx)){// Fetch all metadata propertiesvarproperties=metadata.FindProperties(p=>true);varvalueAcceptor=newCustomValueAcceptor();foreach(varpropertyinproperties){// Extract the property value using a custom acceptorproperty.Value.AcceptValue(valueAcceptor);}}Console.ReadKey();}privateclassCustomValueAcceptor:ValueAcceptor{protectedoverridevoidAcceptNull(){Console.WriteLine("Null value extracted");}protectedoverridevoidAccept(stringvalue){Console.WriteLine("String value extracted: {0}",value);}protectedoverridevoidAccept(boolvalue){Console.WriteLine("Boolean value extracted: {0}",value);}protectedoverridevoidAccept(DateTimevalue){Console.WriteLine("DateTime value extracted: {0}",value);}protectedoverridevoidAccept(TimeSpanvalue){Console.WriteLine("DateTime value extracted: {0}",value);}protectedoverridevoidAccept(intvalue){Console.WriteLine("Integer value extracted: {0}",value);}protectedoverridevoidAccept(longvalue){Console.WriteLine("Long value extracted: {0}",value);}protectedoverridevoidAccept(doublevalue){Console.WriteLine("Double value extracted: {0}",value);}protectedoverridevoidAccept(string[]value){Console.WriteLine("String array extracted: {0}",value?.Length??0);}protectedoverridevoidAccept(byte[]value){Console.WriteLine("Byte array extracted: {0}",value?.Length??0);}protectedoverridevoidAccept(double[]value){Console.WriteLine("Double array extracted: {0}",value?.Length??0);}protectedoverridevoidAccept(int[]value){Console.WriteLine("Integer array extracted: {0}",value?.Length??0);}protectedoverridevoidAccept(long[]value){Console.WriteLine("Long array extracted: {0}",value?.Length??0);}protectedoverridevoidAccept(MetadataPackagevalue){Console.WriteLine("Metadata package value extracted: {0}",value);}protectedoverridevoidAccept(MetadataPackage[]value){Console.WriteLine("Metadata package array extracted: {0}",value?.Length??0);}protectedoverridevoidAccept(Guidvalue){Console.WriteLine("Guid value extracted: {0}",value);}protectedoverridevoidAccept(PropertyValue[]value){Console.WriteLine("Property value array extracted: {0}",value?.Length??0);}}
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.