Aspose::Words::Properties::CustomDocumentProperties class

CustomDocumentProperties class

A collection of custom document properties. To learn more, visit the Work with Document Properties documentation article.

class CustomDocumentProperties : public Aspose::Words::Properties::DocumentPropertyCollection

Methods

MethodDescription
Add(const System::String&, const System::String&)Creates a new custom document property of the String data type.
Add(const System::String&, int32_t)Creates a new custom document property of the Number data type.
Add(const System::String&, System::DateTime)Creates a new custom document property of the DateTime data type.
Add(const System::String&, bool)Creates a new custom document property of the Boolean data type.
Add(const System::String&, double)Creates a new custom document property of the Double data type.
AddLinkToContent(const System::String&, const System::String&)Creates a new linked to content custom document property.
Clear()Removes all properties from the collection.
Contains(const System::String&)Returns true if a property with the specified name exists in the collection.
get_Count()Gets number of items in the collection.
GetEnumerator() overrideReturns an enumerator object that can be used to iterate over all items in the collection.
GetType() const override
virtual idx_get(System::String)Returns a DocumentProperty object by the name of the property.
idx_get(int32_t)Returns a DocumentProperty object by index.
IndexOf(const System::String&)Gets the index of a property by name.
Is(const System::TypeInfo&) const override
Remove(const System::String&)Removes a property with the specified name from the collection.
RemoveAt(int32_t)Removes a property at the specified index.
static Type()

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.

auto doc = MakeObject<Document>(MyDir + u"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_EQ(u"Value of custom document property", System::ObjectExt::ToString(doc->get_CustomDocumentProperties()->idx_get(u"CustomProperty")));

doc->get_CustomDocumentProperties()->Add(u"CustomProperty2", String(u"Value of custom document property #2"));

std::cout << "Custom Properties:" << std::endl;
for (const auto& customDocumentProperty : System::IterateOver(doc->get_CustomDocumentProperties()))
{
    std::cout << customDocumentProperty->get_Name() << std::endl;
    std::cout << String::Format(u"\tType:\t{0}", customDocumentProperty->get_Type()) << std::endl;
    std::cout << "\tValue:\t\"" << customDocumentProperty->get_Value() << "\"" << std::endl;
}

See Also