Aspose::Words::Fields::FieldSubject::set_Text method

FieldSubject::set_Text method

Sets the text of the subject.

void Aspose::Words::Fields::FieldSubject::set_Text(const System::String & value)

Examples

Shows how to use the SUBJECT field.

auto doc = System::MakeObject<Aspose::Words::Document>();

// Set a value for the document's "Subject" built-in property.
doc->get_BuiltInDocumentProperties()->set_Subject(u"My subject");

// Create a SUBJECT field to display the value of that built-in property.
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
auto field = System::ExplicitCast<Aspose::Words::Fields::FieldSubject>(builder->InsertField(FieldType::FieldSubject, true));
field->Update();

ASSERT_EQ(field->GetFieldCode(), u" SUBJECT ");
ASSERT_EQ(field->get_Result(), u"My subject");

// If we give the SUBJECT field's Text property value and update it, the field will
// overwrite the current value of the "Subject" built-in property with the value of its Text property,
// and then display the new value.
field->set_Text(u"My new subject");
field->Update();

ASSERT_EQ(field->GetFieldCode(), u" SUBJECT  \"My new subject\"");
ASSERT_EQ(field->get_Result(), u"My new subject");

ASSERT_EQ(doc->get_BuiltInDocumentProperties()->get_Subject(), u"My new subject");

doc->Save(get_ArtifactsDir() + u"Field.SUBJECT.docx");

See Also