Aspose::Words::Fields::Field::get_DisplayResult method

Field::get_DisplayResult method

Gets the text that represents the displayed field result.

System::String Aspose::Words::Fields::Field::get_DisplayResult()

Remarks

The UpdateListLabels method must be called to obtain correct value for the FieldListNum, FieldAutoNum, FieldAutoNumOut and FieldAutoNumLgl fields.

Examples

Shows how to get the real text that a field displays in the document.

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

builder->Write(u"This document was written by ");
auto fieldAuthor = System::ExplicitCast<Aspose::Words::Fields::FieldAuthor>(builder->InsertField(FieldType::FieldAuthor, true));
fieldAuthor->set_AuthorName(u"John Doe");

// We can use the DisplayResult property to verify what exact text
// a field would display in its place in the document.
ASSERT_EQ(fieldAuthor->get_DisplayResult(), System::String::Empty);

// Fields do not maintain accurate result values in real-time.
// To make sure our fields display accurate results at any given time,
// such as right before a save operation, we need to update them manually.
fieldAuthor->Update();

ASSERT_EQ(fieldAuthor->get_DisplayResult(), u"John Doe");

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

See Also