Aspose::Words::Properties::CustomDocumentProperties Class Reference

Detailed Description

A collection of custom document properties.

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.

See also
Aspose::Words::Document
Aspose::Words::Document::get_BuiltInDocumentProperties
Aspose::Words::Document::get_CustomDocumentProperties
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 (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;
}

#include <Aspose.Words.Cpp/Properties/CustomDocumentProperties.h>

+ Inheritance diagram for Aspose::Words::Properties::CustomDocumentProperties:

Public Member Functions

SharedPtr< DocumentPropertyAdd (String name, bool value)
 Creates a new custom document property of the PropertyType.Boolean data type. More...
 
SharedPtr< DocumentPropertyAdd (String name, double value)
 Creates a new custom document property of the PropertyType.Float data type. More...
 
SharedPtr< DocumentPropertyAdd (String name, int32_t value)
 Creates a new custom document property of the PropertyType.Number data type. More...
 
SharedPtr< DocumentPropertyAdd (String name, DateTime value)
 Creates a new custom document property of the PropertyType.DateTime data type. More...
 
SharedPtr< DocumentPropertyAdd (String name, String value)
 Creates a new custom document property of the PropertyType.String data type. More...
 
SharedPtr< DocumentPropertyAddLinkToContent (String name, String linkSource)
 Creates a new linked to content custom document property. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
- Public Member Functions inherited from DocumentPropertyCollection
void Clear ()
 Removes all properties from the collection. More...
 
bool Contains (String name)
 Returns true if a property with the specified name exists in the collection. More...
 
int32_t get_Count ()
 Gets number of items in the collection. More...
 
SharedPtr< IEnumerator< SharedPtr< DocumentProperty > > > GetEnumerator () override
 Returns an enumerator object that can be used to iterate over all items in the collection. More...
 
SharedPtr< DocumentPropertyidx_get (int32_t index)
 Returns a DocumentProperty object by index. More...
 
virtual SharedPtr< DocumentPropertyidx_get (String name)
 Returns a DocumentProperty object by the name of the property. More...
 
int32_t IndexOf (String name)
 Gets the index of a property by name. More...
 
void Remove (String name)
 Removes a property with the specified name from the collection. More...
 
void RemoveAt (int32_t index)
 Removes a property at the specified index. More...
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from DocumentPropertyCollection
static const TypeInfoType ()
 

Member Function Documentation

◆ Add() [1/5]

System::SharedPtr<Aspose::Words::Properties::DocumentProperty> Aspose::Words::Properties::CustomDocumentProperties::Add ( System::String  name,
bool  value 
)

Creates a new custom document property of the PropertyType.Boolean data type.

Parameters
nameThe name of the property.
valueThe value of the property.
Returns
The newly created property object.
Examples

Shows how to work with a document's custom properties.

auto doc = MakeObject<Document>();
SharedPtr<CustomDocumentProperties> properties = doc->get_CustomDocumentProperties();
ASSERT_EQ(0, properties->get_Count());
// Custom document properties are key-value pairs that we can add to the document.
properties->Add(u"Authorized", true);
properties->Add(u"Authorized By", String(u"John Doe"));
properties->Add(u"Authorized Date", System::DateTime::get_Today());
properties->Add(u"Authorized Revision", doc->get_BuiltInDocumentProperties()->get_RevisionNumber());
properties->Add(u"Authorized Amount", 123.45);
// The collection sorts the custom properties in alphabetic order.
ASSERT_EQ(1, properties->IndexOf(u"Authorized Amount"));
ASSERT_EQ(5, properties->get_Count());
// Print every custom property in the document.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<DocumentProperty>>> enumerator = properties->GetEnumerator();
while (enumerator->MoveNext())
{
std::cout << String::Format(u"Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", enumerator->get_Current()->get_Name(),
enumerator->get_Current()->get_Type(), enumerator->get_Current()->get_Value())
<< std::endl;
}
}
// Display the value of a custom property using a DOCPROPERTY field.
auto builder = MakeObject<DocumentBuilder>(doc);
auto field = System::DynamicCast<FieldDocProperty>(builder->InsertField(u" DOCPROPERTY \"Authorized By\""));
field->Update();
ASSERT_EQ(u"John Doe", field->get_Result());
// We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
doc->Save(ArtifactsDir + u"DocumentProperties.DocumentPropertyCollection.docx");
// Below are three ways or removing custom properties from a document.
// 1 - Remove by index:
properties->RemoveAt(1);
ASSERT_FALSE(properties->Contains(u"Authorized Amount"));
ASSERT_EQ(4, properties->get_Count());
// 2 - Remove by name:
properties->Remove(u"Authorized Revision");
ASSERT_FALSE(properties->Contains(u"Authorized Revision"));
ASSERT_EQ(3, properties->get_Count());
// 3 - Empty the entire collection at once:
properties->Clear();
ASSERT_EQ(0, properties->get_Count());

◆ Add() [2/5]

System::SharedPtr<Aspose::Words::Properties::DocumentProperty> Aspose::Words::Properties::CustomDocumentProperties::Add ( System::String  name,
double  value 
)

Creates a new custom document property of the PropertyType.Float data type.

Parameters
nameThe name of the property.
valueThe value of the property.
Returns
The newly created property object.
Examples

Shows how to work with a document's custom properties.

auto doc = MakeObject<Document>();
SharedPtr<CustomDocumentProperties> properties = doc->get_CustomDocumentProperties();
ASSERT_EQ(0, properties->get_Count());
// Custom document properties are key-value pairs that we can add to the document.
properties->Add(u"Authorized", true);
properties->Add(u"Authorized By", String(u"John Doe"));
properties->Add(u"Authorized Date", System::DateTime::get_Today());
properties->Add(u"Authorized Revision", doc->get_BuiltInDocumentProperties()->get_RevisionNumber());
properties->Add(u"Authorized Amount", 123.45);
// The collection sorts the custom properties in alphabetic order.
ASSERT_EQ(1, properties->IndexOf(u"Authorized Amount"));
ASSERT_EQ(5, properties->get_Count());
// Print every custom property in the document.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<DocumentProperty>>> enumerator = properties->GetEnumerator();
while (enumerator->MoveNext())
{
std::cout << String::Format(u"Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", enumerator->get_Current()->get_Name(),
enumerator->get_Current()->get_Type(), enumerator->get_Current()->get_Value())
<< std::endl;
}
}
// Display the value of a custom property using a DOCPROPERTY field.
auto builder = MakeObject<DocumentBuilder>(doc);
auto field = System::DynamicCast<FieldDocProperty>(builder->InsertField(u" DOCPROPERTY \"Authorized By\""));
field->Update();
ASSERT_EQ(u"John Doe", field->get_Result());
// We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
doc->Save(ArtifactsDir + u"DocumentProperties.DocumentPropertyCollection.docx");
// Below are three ways or removing custom properties from a document.
// 1 - Remove by index:
properties->RemoveAt(1);
ASSERT_FALSE(properties->Contains(u"Authorized Amount"));
ASSERT_EQ(4, properties->get_Count());
// 2 - Remove by name:
properties->Remove(u"Authorized Revision");
ASSERT_FALSE(properties->Contains(u"Authorized Revision"));
ASSERT_EQ(3, properties->get_Count());
// 3 - Empty the entire collection at once:
properties->Clear();
ASSERT_EQ(0, properties->get_Count());

◆ Add() [3/5]

System::SharedPtr<Aspose::Words::Properties::DocumentProperty> Aspose::Words::Properties::CustomDocumentProperties::Add ( System::String  name,
int32_t  value 
)

Creates a new custom document property of the PropertyType.Number data type.

Parameters
nameThe name of the property.
valueThe value of the property.
Returns
The newly created property object.
Examples

Shows how to work with a document's custom properties.

auto doc = MakeObject<Document>();
SharedPtr<CustomDocumentProperties> properties = doc->get_CustomDocumentProperties();
ASSERT_EQ(0, properties->get_Count());
// Custom document properties are key-value pairs that we can add to the document.
properties->Add(u"Authorized", true);
properties->Add(u"Authorized By", String(u"John Doe"));
properties->Add(u"Authorized Date", System::DateTime::get_Today());
properties->Add(u"Authorized Revision", doc->get_BuiltInDocumentProperties()->get_RevisionNumber());
properties->Add(u"Authorized Amount", 123.45);
// The collection sorts the custom properties in alphabetic order.
ASSERT_EQ(1, properties->IndexOf(u"Authorized Amount"));
ASSERT_EQ(5, properties->get_Count());
// Print every custom property in the document.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<DocumentProperty>>> enumerator = properties->GetEnumerator();
while (enumerator->MoveNext())
{
std::cout << String::Format(u"Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", enumerator->get_Current()->get_Name(),
enumerator->get_Current()->get_Type(), enumerator->get_Current()->get_Value())
<< std::endl;
}
}
// Display the value of a custom property using a DOCPROPERTY field.
auto builder = MakeObject<DocumentBuilder>(doc);
auto field = System::DynamicCast<FieldDocProperty>(builder->InsertField(u" DOCPROPERTY \"Authorized By\""));
field->Update();
ASSERT_EQ(u"John Doe", field->get_Result());
// We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
doc->Save(ArtifactsDir + u"DocumentProperties.DocumentPropertyCollection.docx");
// Below are three ways or removing custom properties from a document.
// 1 - Remove by index:
properties->RemoveAt(1);
ASSERT_FALSE(properties->Contains(u"Authorized Amount"));
ASSERT_EQ(4, properties->get_Count());
// 2 - Remove by name:
properties->Remove(u"Authorized Revision");
ASSERT_FALSE(properties->Contains(u"Authorized Revision"));
ASSERT_EQ(3, properties->get_Count());
// 3 - Empty the entire collection at once:
properties->Clear();
ASSERT_EQ(0, properties->get_Count());

◆ Add() [4/5]

System::SharedPtr<Aspose::Words::Properties::DocumentProperty> Aspose::Words::Properties::CustomDocumentProperties::Add ( System::String  name,
System::DateTime  value 
)

Creates a new custom document property of the PropertyType.DateTime data type.

Parameters
nameThe name of the property.
valueThe value of the property.
Returns
The newly created property object.
Examples

Shows how to create a custom document property which contains a date and time.

auto doc = MakeObject<Document>();
doc->get_CustomDocumentProperties()->Add(u"AuthorizationDate", System::DateTime::get_Now());
std::cout << "Document authorized on " << doc->get_CustomDocumentProperties()->idx_get(u"AuthorizationDate")->ToDateTime() << std::endl;

Shows how to work with a document's custom properties.

auto doc = MakeObject<Document>();
SharedPtr<CustomDocumentProperties> properties = doc->get_CustomDocumentProperties();
ASSERT_EQ(0, properties->get_Count());
// Custom document properties are key-value pairs that we can add to the document.
properties->Add(u"Authorized", true);
properties->Add(u"Authorized By", String(u"John Doe"));
properties->Add(u"Authorized Date", System::DateTime::get_Today());
properties->Add(u"Authorized Revision", doc->get_BuiltInDocumentProperties()->get_RevisionNumber());
properties->Add(u"Authorized Amount", 123.45);
// The collection sorts the custom properties in alphabetic order.
ASSERT_EQ(1, properties->IndexOf(u"Authorized Amount"));
ASSERT_EQ(5, properties->get_Count());
// Print every custom property in the document.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<DocumentProperty>>> enumerator = properties->GetEnumerator();
while (enumerator->MoveNext())
{
std::cout << String::Format(u"Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", enumerator->get_Current()->get_Name(),
enumerator->get_Current()->get_Type(), enumerator->get_Current()->get_Value())
<< std::endl;
}
}
// Display the value of a custom property using a DOCPROPERTY field.
auto builder = MakeObject<DocumentBuilder>(doc);
auto field = System::DynamicCast<FieldDocProperty>(builder->InsertField(u" DOCPROPERTY \"Authorized By\""));
field->Update();
ASSERT_EQ(u"John Doe", field->get_Result());
// We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
doc->Save(ArtifactsDir + u"DocumentProperties.DocumentPropertyCollection.docx");
// Below are three ways or removing custom properties from a document.
// 1 - Remove by index:
properties->RemoveAt(1);
ASSERT_FALSE(properties->Contains(u"Authorized Amount"));
ASSERT_EQ(4, properties->get_Count());
// 2 - Remove by name:
properties->Remove(u"Authorized Revision");
ASSERT_FALSE(properties->Contains(u"Authorized Revision"));
ASSERT_EQ(3, properties->get_Count());
// 3 - Empty the entire collection at once:
properties->Clear();
ASSERT_EQ(0, properties->get_Count());

◆ Add() [5/5]

System::SharedPtr<Aspose::Words::Properties::DocumentProperty> Aspose::Words::Properties::CustomDocumentProperties::Add ( System::String  name,
System::String  value 
)

Creates a new custom document property of the PropertyType.String data type.

Parameters
nameThe name of the property.
valueThe value of the property.
Returns
The newly created property object.
Examples

Shows how to work with a document's custom properties.

auto doc = MakeObject<Document>();
SharedPtr<CustomDocumentProperties> properties = doc->get_CustomDocumentProperties();
ASSERT_EQ(0, properties->get_Count());
// Custom document properties are key-value pairs that we can add to the document.
properties->Add(u"Authorized", true);
properties->Add(u"Authorized By", String(u"John Doe"));
properties->Add(u"Authorized Date", System::DateTime::get_Today());
properties->Add(u"Authorized Revision", doc->get_BuiltInDocumentProperties()->get_RevisionNumber());
properties->Add(u"Authorized Amount", 123.45);
// The collection sorts the custom properties in alphabetic order.
ASSERT_EQ(1, properties->IndexOf(u"Authorized Amount"));
ASSERT_EQ(5, properties->get_Count());
// Print every custom property in the document.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<DocumentProperty>>> enumerator = properties->GetEnumerator();
while (enumerator->MoveNext())
{
std::cout << String::Format(u"Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", enumerator->get_Current()->get_Name(),
enumerator->get_Current()->get_Type(), enumerator->get_Current()->get_Value())
<< std::endl;
}
}
// Display the value of a custom property using a DOCPROPERTY field.
auto builder = MakeObject<DocumentBuilder>(doc);
auto field = System::DynamicCast<FieldDocProperty>(builder->InsertField(u" DOCPROPERTY \"Authorized By\""));
field->Update();
ASSERT_EQ(u"John Doe", field->get_Result());
// We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
doc->Save(ArtifactsDir + u"DocumentProperties.DocumentPropertyCollection.docx");
// Below are three ways or removing custom properties from a document.
// 1 - Remove by index:
properties->RemoveAt(1);
ASSERT_FALSE(properties->Contains(u"Authorized Amount"));
ASSERT_EQ(4, properties->get_Count());
// 2 - Remove by name:
properties->Remove(u"Authorized Revision");
ASSERT_FALSE(properties->Contains(u"Authorized Revision"));
ASSERT_EQ(3, properties->get_Count());
// 3 - Empty the entire collection at once:
properties->Clear();
ASSERT_EQ(0, properties->get_Count());

◆ AddLinkToContent()

System::SharedPtr<Aspose::Words::Properties::DocumentProperty> Aspose::Words::Properties::CustomDocumentProperties::AddLinkToContent ( System::String  name,
System::String  linkSource 
)

Creates a new linked to content custom document property.

Parameters
nameThe name of the property.
linkSourceThe source of the property.
Returns
The newly created property object or null when the linkSource is invalid.
Examples

Shows how to link a custom document property to a bookmark.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->StartBookmark(u"MyBookmark");
builder->Write(u"Hello world!");
builder->EndBookmark(u"MyBookmark");
// Link a new custom property to a bookmark. The value of this property
// will be the contents of the bookmark that it references in the "LinkSource" member.
SharedPtr<CustomDocumentProperties> customProperties = doc->get_CustomDocumentProperties();
SharedPtr<DocumentProperty> customProperty = customProperties->AddLinkToContent(u"Bookmark", u"MyBookmark");
ASPOSE_ASSERT_EQ(true, customProperty->get_IsLinkToContent());
ASSERT_EQ(u"MyBookmark", customProperty->get_LinkSource());
ASPOSE_ASSERT_EQ(u"Hello world!", customProperty->get_Value());
doc->Save(ArtifactsDir + u"DocumentProperties.LinkCustomDocumentPropertiesToBookmark.docx");

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Properties::CustomDocumentProperties::GetType ( ) const
overridevirtual

◆ Is()

virtual bool Aspose::Words::Properties::CustomDocumentProperties::Is ( const System::TypeInfo target) const
overridevirtual

◆ Type()

static const System::TypeInfo& Aspose::Words::Properties::CustomDocumentProperties::Type ( )
static