CustomDocumentProperties

CustomDocumentProperties class

A collection of custom document properties.

To learn more, visit the Work with Document Properties documentation article.

public class CustomDocumentProperties : DocumentPropertyCollection

Properties

NameDescription
Count { get; }Gets number of items in the collection.
Item { get; }Returns a DocumentProperty object by index.
virtual Item { get; }Returns a DocumentProperty object by the name of the property.

Methods

NameDescription
Add(string, bool)Creates a new custom document property of the Boolean data type.
Add(string, DateTime)Creates a new custom document property of the DateTime data type.
Add(string, double)Creates a new custom document property of the Double data type.
Add(string, int)Creates a new custom document property of the Number data type.
Add(string, string)Creates a new custom document property of the String data type.
AddLinkToContent(string, string)Creates a new linked to content custom document property.
Clear()Removes all properties from the collection.
Contains(string)Returns true if a property with the specified name exists in the collection.
GetEnumerator()Returns an enumerator object that can be used to iterate over all items in the collection.
IndexOf(string)Gets the index of a property by name.
Remove(string)Removes a property with the specified name from the collection.
RemoveAt(int)Removes a property at the specified index.

Remarks

Each DocumentProperty object represents a custom property of a container document.

The names of the properties are case-insensitive.

The properties in the collection are sorted alphabetically by name.

Examples

Shows how to work with custom document properties.

Document doc = new Document(MyDir + "Properties.docx");

// Every document contains a collection of custom properties, which, like the built-in properties, are key-value pairs.
// The document has a fixed list of built-in properties. The user creates all of the custom properties. 
Assert.AreEqual("Value of custom document property", doc.CustomDocumentProperties["CustomProperty"].ToString());

doc.CustomDocumentProperties.Add("CustomProperty2", "Value of custom document property #2");

Console.WriteLine("Custom Properties:");
foreach (var customDocumentProperty in doc.CustomDocumentProperties)
{
    Console.WriteLine(customDocumentProperty.Name);
    Console.WriteLine($"\tType:\t{customDocumentProperty.Type}");
    Console.WriteLine($"\tValue:\t\"{customDocumentProperty.Value}\"");
}

See Also