Aspose::Words::Properties::DocumentPropertyCollection Class Referenceabstract

Detailed Description

Base class for BuiltInDocumentProperties and CustomDocumentProperties collections.

The names of the properties are case-insensitive.

The properties in the collection are sorted alphabetically by name.

See also
Aspose::Words::Properties::BuiltInDocumentProperties
Aspose::Words::Properties::CustomDocumentProperties
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());

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

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

Public Member Functions

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...
 
virtual const TypeInfoGetType () const override
 
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...
 
virtual bool Is (const TypeInfo &target) const override
 
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 ()
 

Member Function Documentation

◆ Clear()

void Aspose::Words::Properties::DocumentPropertyCollection::Clear ( )

Removes all properties from the collection.

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());

◆ Contains()

bool Aspose::Words::Properties::DocumentPropertyCollection::Contains ( System::String  name)

Returns true if a property with the specified name exists in the collection.

Parameters
nameThe case-insensitive name of the property.
Returns
True if the property exists in the collection; false otherwise.
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());

◆ get_Count()

int32_t Aspose::Words::Properties::DocumentPropertyCollection::get_Count ( )

Gets number of items in the collection.

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;
}

◆ GetEnumerator()

System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Aspose::Words::Properties::DocumentProperty> > > Aspose::Words::Properties::DocumentPropertyCollection::GetEnumerator ( )
override

Returns an enumerator object that can be used to iterate over all items in the collection.

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());

◆ GetType()

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

◆ idx_get() [1/2]

System::SharedPtr<Aspose::Words::Properties::DocumentProperty> Aspose::Words::Properties::DocumentPropertyCollection::idx_get ( int32_t  index)

Returns a DocumentProperty object by index.

Parameters
indexZero-based index of the DocumentProperty to retrieve.
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;
}

◆ idx_get() [2/2]

virtual System::SharedPtr<Aspose::Words::Properties::DocumentProperty> Aspose::Words::Properties::DocumentPropertyCollection::idx_get ( System::String  name)
virtual

Returns a DocumentProperty object by the name of the property.

Returns null if a property with the specified name is not found.

Parameters
nameThe case-insensitive name of the property to retrieve.
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;

Reimplemented in Aspose::Words::Properties::BuiltInDocumentProperties.

◆ IndexOf()

int32_t Aspose::Words::Properties::DocumentPropertyCollection::IndexOf ( System::String  name)

Gets the index of a property by name.

Parameters
nameThe case-insensitive name of the property.
Returns
The zero based index. Negative value if not found.
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());

◆ Is()

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

◆ Remove()

void Aspose::Words::Properties::DocumentPropertyCollection::Remove ( System::String  name)

Removes a property with the specified name from the collection.

Parameters
nameThe case-insensitive name of the property.
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());

◆ RemoveAt()

void Aspose::Words::Properties::DocumentPropertyCollection::RemoveAt ( int32_t  index)

Removes a property at the specified index.

Parameters
indexThe zero based index.
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());

◆ Type()

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