Aspose::Words::Fields::FieldLink class

Implements the LINK field. To learn more, visit the Working with Fields documentation article.

class FieldLink : public Aspose::Words::Fields::Field,
                  public Aspose::Words::Fields::IFieldCodeTokenInfoProvider

Methods

MethodDescription
get_AutoUpdate()Gets or sets whether to update this field automatically.
get_DisplayResult()Gets the text that represents the displayed field result.
get_End() constGets the node that represents the field end.
get_FieldEnd() constGets the node that represents the field end.
get_FieldStart() constGets the node that represents the start of the field.
get_Format()Gets a FieldFormat object that provides typed access to field’s formatting.
get_FormatUpdateType()Gets or sets a way the linked object updates its formatting.
get_InsertAsBitmap()Gets or sets whether to insert the linked object as a bitmap.
get_InsertAsHtml()Gets or sets whether to insert the linked object as HTML format text.
get_InsertAsPicture()Gets or sets whether to insert the linked object as a picture.
get_InsertAsRtf()Gets or sets whether to insert the linked object in rich-text format (RTF).
get_InsertAsText()Gets or sets whether to insert the linked object in text-only format.
get_InsertAsUnicode()Gets or sets whether to insert the linked object as Unicode text.
get_IsDirty()Gets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
get_IsLinked()Gets or sets whether to reduce the file size by not storing graphics data with the document.
get_IsLocked()Gets or sets whether the field is locked (should not recalculate its result).
get_LocaleId()Gets or sets the LCID of the field.
get_ProgId()Gets or sets the application type of the link information.
get_Result()Gets or sets text that is between the field separator and field end.
get_Separator()Gets the node that represents the field separator. Can be null.
get_SourceFullName()Gets or sets the name and location of the source file.
get_SourceItem()Gets or sets the portion of the source file that’s being linked.
get_Start() constGets the node that represents the start of the field.
virtual get_Type() constGets the Microsoft Word field type.
GetFieldCode()Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included.
GetFieldCode(bool)Returns text between field start and field separator (or field end if there is no separator).
GetType() const override
Is(const System::TypeInfo&) const override
Remove()Removes the field from the document. Returns a node right after the field. If the field’s end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns null.
set_AutoUpdate(bool)Setter for Aspose::Words::Fields::FieldLink::get_AutoUpdate.
set_FormatUpdateType(const System::String&)Setter for Aspose::Words::Fields::FieldLink::get_FormatUpdateType.
set_InsertAsBitmap(bool)Setter for Aspose::Words::Fields::FieldLink::get_InsertAsBitmap.
set_InsertAsHtml(bool)Setter for Aspose::Words::Fields::FieldLink::get_InsertAsHtml.
set_InsertAsPicture(bool)Setter for Aspose::Words::Fields::FieldLink::get_InsertAsPicture.
set_InsertAsRtf(bool)Setter for Aspose::Words::Fields::FieldLink::get_InsertAsRtf.
set_InsertAsText(bool)Setter for Aspose::Words::Fields::FieldLink::get_InsertAsText.
set_InsertAsUnicode(bool)Setter for Aspose::Words::Fields::FieldLink::get_InsertAsUnicode.
set_IsDirty(bool)Sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
set_IsLinked(bool)Setter for Aspose::Words::Fields::FieldLink::get_IsLinked.
set_IsLocked(bool)Setter for Aspose::Words::Fields::Field::get_IsLocked.
set_LocaleId(int32_t)Setter for Aspose::Words::Fields::Field::get_LocaleId.
set_ProgId(const System::String&)Setter for Aspose::Words::Fields::FieldLink::get_ProgId.
set_Result(const System::String&)Setter for Aspose::Words::Fields::Field::get_Result.
set_SourceFullName(const System::String&)Setter for Aspose::Words::Fields::FieldLink::get_SourceFullName.
set_SourceItem(const System::String&)Setter for Aspose::Words::Fields::FieldLink::get_SourceItem.
static Type()
Unlink()Performs the field unlink.
Update()Performs the field update. Throws if the field is being updated already.
Update(bool)Performs a field update. Throws if the field is being updated already.

Examples

Shows how to use various field types to link to other documents in the local file system, and display their contents.

enum class InsertLinkedObjectAs
{
    Text,
    Unicode,
    Html,
    Rtf,
    Picture,
    Bitmap
};

static void InsertFieldLink(SharedPtr<DocumentBuilder> builder, ExField::InsertLinkedObjectAs insertLinkedObjectAs, String progId, String sourceFullName,
                            String sourceItem, bool shouldAutoUpdate)
{
    auto field = System::ExplicitCast<FieldLink>(builder->InsertField(FieldType::FieldLink, true));

    switch (insertLinkedObjectAs)
    {
    case ApiExamples::ExField::InsertLinkedObjectAs::Text:
        field->set_InsertAsText(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Unicode:
        field->set_InsertAsUnicode(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Html:
        field->set_InsertAsHtml(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Rtf:
        field->set_InsertAsRtf(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Picture:
        field->set_InsertAsPicture(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Bitmap:
        field->set_InsertAsBitmap(true);
        break;
    }

    field->set_AutoUpdate(shouldAutoUpdate);
    field->set_ProgId(progId);
    field->set_SourceFullName(sourceFullName);
    field->set_SourceItem(sourceItem);

    builder->Writeln(u"\n");
}

static void InsertFieldDde(SharedPtr<DocumentBuilder> builder, ExField::InsertLinkedObjectAs insertLinkedObjectAs, String progId, String sourceFullName,
                           String sourceItem, bool isLinked, bool shouldAutoUpdate)
{
    auto field = System::ExplicitCast<FieldDde>(builder->InsertField(FieldType::FieldDDE, true));

    switch (insertLinkedObjectAs)
    {
    case ApiExamples::ExField::InsertLinkedObjectAs::Text:
        field->set_InsertAsText(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Unicode:
        field->set_InsertAsUnicode(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Html:
        field->set_InsertAsHtml(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Rtf:
        field->set_InsertAsRtf(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Picture:
        field->set_InsertAsPicture(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Bitmap:
        field->set_InsertAsBitmap(true);
        break;
    }

    field->set_AutoUpdate(shouldAutoUpdate);
    field->set_ProgId(progId);
    field->set_SourceFullName(sourceFullName);
    field->set_SourceItem(sourceItem);
    field->set_IsLinked(isLinked);

    builder->Writeln(u"\n");
}

static void InsertFieldDdeAuto(SharedPtr<DocumentBuilder> builder, ExField::InsertLinkedObjectAs insertLinkedObjectAs, String progId, String sourceFullName,
                               String sourceItem, bool isLinked)
{
    auto field = System::ExplicitCast<FieldDdeAuto>(builder->InsertField(FieldType::FieldDDEAuto, true));

    switch (insertLinkedObjectAs)
    {
    case ApiExamples::ExField::InsertLinkedObjectAs::Text:
        field->set_InsertAsText(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Unicode:
        field->set_InsertAsUnicode(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Html:
        field->set_InsertAsHtml(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Rtf:
        field->set_InsertAsRtf(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Picture:
        field->set_InsertAsPicture(true);
        break;

    case ApiExamples::ExField::InsertLinkedObjectAs::Bitmap:
        field->set_InsertAsBitmap(true);
        break;
    }

    field->set_ProgId(progId);
    field->set_SourceFullName(sourceFullName);
    field->set_SourceItem(sourceItem);
    field->set_IsLinked(isLinked);
}

See Also