DocumentPropertyCollection Class

Base class for BuiltInDocumentProperties and CustomDocumentProperties collections.
Inheritance Hierarchy

Namespace:  Aspose.Words.Properties
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public abstract class DocumentPropertyCollection : IEnumerable<DocumentProperty>, 
	IEnumerable

The DocumentPropertyCollection type exposes the following members.

Properties
Methods
  NameDescription
Public methodCode exampleClear
Removes all properties from the collection.
Public methodCode exampleContains
Returns true if a property with the specified name exists in the collection.
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetEnumerator
Returns an enumerator object that can be used to iterate over all items in the collection.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleIndexOf
Gets the index of a property by name.
Public methodCode exampleRemove
Removes a property with the specified name from the collection.
Public methodCode exampleRemoveAt
Removes a property at the specified index.
Public methodToString (Inherited from Object.)
Remarks
Remarks

The names of the properties are case-insensitive.

The properties in the collection are sorted alphabetically by name.

Examples
Shows how to add custom properties to a document.
// Create a blank document and get its custom property collection
Document doc = new Document();
CustomDocumentProperties properties = doc.CustomDocumentProperties;

// The collection will be empty by default
Assert.AreEqual(0, properties.Count);

// We can populate it with key/value pairs with a variety of value types
properties.Add("Authorized", true);
properties.Add("Authorized By", "John Doe");
properties.Add("Authorized Date", DateTime.Today);
properties.Add("Authorized Revision", doc.BuiltInDocumentProperties.RevisionNumber);
properties.Add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.AreEqual(1, properties.IndexOf("Authorized Amount"));
Assert.AreEqual(5, properties.Count);

// Enumerate and print all custom properties
using (IEnumerator<DocumentProperty> enumerator = properties.GetEnumerator())
{
    while (enumerator.MoveNext())
    {
        Console.WriteLine($"Name: \"{enumerator.Current.Name}\", Type: \"{enumerator.Current.Type}\", Value: \"{enumerator.Current.Value}\"");
    }
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.Save(ArtifactsDir + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.RemoveAt(1);
Assert.False(properties.Contains("Authorized Amount"));
Assert.AreEqual(4, properties.Count);

properties.Remove("Authorized Revision");
Assert.False(properties.Contains("Authorized Revision"));
Assert.AreEqual(3, properties.Count);

// We can also empty the entire custom property collection at once
properties.Clear();
Assert.AreEqual(0, properties.Count);
See Also