DocumentPropertyCollection Class |
Namespace: Aspose.Words.Properties
The DocumentPropertyCollection type exposes the following members.
| Name | Description | |
|---|---|---|
| Count |
Gets number of items in the collection.
| |
| ItemInt32 |
Returns a DocumentProperty object by index.
| |
| ItemString |
Returns a DocumentProperty object by the name of the property.
|
| Name | Description | |
|---|---|---|
| Clear |
Removes all properties from the collection.
| |
| Contains |
Returns true if a property with the specified name exists in the collection.
| |
| Equals | (Inherited from Object.) | |
| GetEnumerator |
Returns an enumerator object that can be used to iterate over all items in the collection.
| |
| GetHashCode | (Inherited from Object.) | |
| GetType | (Inherited from Object.) | |
| IndexOf |
Gets the index of a property by name.
| |
| Remove |
Removes a property with the specified name from the collection.
| |
| RemoveAt |
Removes a property at the specified index.
| |
| ToString | (Inherited from Object.) |
The names of the properties are case-insensitive.
The properties in the collection are sorted alphabetically by name.
// 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);