Aspose::Words::Properties Namespace Reference

Detailed Description

The Aspose.Words.Properties namespace provides classes to work with custom and built-in document properties such as title, keywords, company etc.

Classes

class  BuiltInDocumentProperties
 A collection of built-in document properties. More...
 
class  CustomDocumentProperties
 A collection of custom document properties. More...
 
class  DocumentProperty
 Represents a custom or built-in document property. More...
 
class  DocumentPropertyCollection
 Base class for BuiltInDocumentProperties and CustomDocumentProperties collections. More...
 

Enumerations

enum class  DocumentSecurity
 Used as a value for the Security property. Specifies the security level of a document as a numeric value. More...
 
enum class  PropertyType
 Specifies data type of a document property. More...
 

Enumeration Type Documentation

◆ DocumentSecurity

Used as a value for the Security property. Specifies the security level of a document as a numeric value.

Examples

Shows how to use document properties to display the security level of a document.

auto doc = MakeObject<Document>();
ASSERT_EQ(DocumentSecurity::None, doc->get_BuiltInDocumentProperties()->get_Security());
// If we configure a document to be read-only, it will display this status using the "Security" built-in property.
doc->get_WriteProtection()->set_ReadOnlyRecommended(true);
doc->Save(ArtifactsDir + u"DocumentProperties.Security.ReadOnlyRecommended.docx");
ASSERT_EQ(
MakeObject<Document>(ArtifactsDir + u"DocumentProperties.Security.ReadOnlyRecommended.docx")->get_BuiltInDocumentProperties()->get_Security());
// Write-protect a document, and then verify its security level.
doc = MakeObject<Document>();
ASSERT_FALSE(doc->get_WriteProtection()->get_IsWriteProtected());
doc->get_WriteProtection()->SetPassword(u"MyPassword");
ASSERT_TRUE(doc->get_WriteProtection()->ValidatePassword(u"MyPassword"));
ASSERT_TRUE(doc->get_WriteProtection()->get_IsWriteProtected());
doc->Save(ArtifactsDir + u"DocumentProperties.Security.ReadOnlyEnforced.docx");
MakeObject<Document>(ArtifactsDir + u"DocumentProperties.Security.ReadOnlyEnforced.docx")->get_BuiltInDocumentProperties()->get_Security());
// "Security" is a descriptive property. We can edit its value manually.
doc = MakeObject<Document>();
doc->Protect(ProtectionType::AllowOnlyComments, u"MyPassword");
doc->get_BuiltInDocumentProperties()->set_Security(DocumentSecurity::ReadOnlyExceptAnnotations);
doc->Save(ArtifactsDir + u"DocumentProperties.Security.ReadOnlyExceptAnnotations.docx");
MakeObject<Document>(ArtifactsDir + u"DocumentProperties.Security.ReadOnlyExceptAnnotations.docx")
->get_BuiltInDocumentProperties()
->get_Security());
Enumerator
None 

There are no security states specified by the property.

PasswordProtected 

The document is password protected. (Note has never been seen in a document so far).

ReadOnlyRecommended 

The document to be opened read-only if possible, but the setting can be overridden.

ReadOnlyEnforced 

The document to always be opened read-only.

ReadOnlyExceptAnnotations 

The document to always be opened read-only except for annotations.

◆ PropertyType

Specifies data type of a document property.

See also
Aspose::Words::Properties::DocumentProperty
Aspose::Words::Properties::DocumentProperty::get_Type
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());
Enumerator
Boolean 

The property is a boolean value.

DateTime 

The property is a date time value.

Double 

The property is a floating number.

Number 

The property is an integer number.

String 

The property is a string value.

StringArray 

The property is an array of strings.

ObjectArray 

The property is an array of objects.

ByteArray 

The property is an array of bytes.

Other 

The property is some other type.