Share via


SmartTagRecognizeContext.PersistTag(ISmartTagProperties) Method

Definition

Stores information about the smart tag. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010..

public void PersistTag (Microsoft.Office.Interop.SmartTag.ISmartTagProperties propertyBag = default);
abstract member PersistTag : Microsoft.Office.Interop.SmartTag.ISmartTagProperties -> unit
Public Sub PersistTag (Optional propertyBag As ISmartTagProperties = Nothing)

Parameters

propertyBag
ISmartTagProperties

A property bag containing key and value pairs for the token. Can be null.

Exceptions

Examples

The following code example demonstrates how to call PersistTag from an implementation of the Recognize method. This implementation compares each smart tag term to the contents of the cell. For each smart tag term in the cell, the code adds a custom smart tag property and then uses the PersistTag method to recognize the smart tag. This example assumes that you have added a reference to Microsoft.Office.Interop.SmartTag from the .NET tab of the Add Reference dialog box. This code example is part of a larger example provided for the ISmartTagExtension interface.

void ISmartTagExtension.Recognize(string text, ISmartTagRecognizerSite site, 
    ISmartTagTokenList tokenList, SmartTagRecognizeContext context)
{

    // Determine whether each smart tag term exists in the document text.
    foreach (string term in smartTagDemo.Terms)
    {
        // Search the cell text for the first instance of the current smart tag term.
        int index = context.CellText.IndexOf(term, 0);

        if (index >= 0)
        {
            // Create a smart tag token and a property bag for the recognized term.
            ISmartTagProperties propertyBag = site.GetNewPropertyBag();

            // Write a new property value.                 
            string key = "Key1";
            propertyBag.Write(key, DateTime.Now.ToString());

            // Attach the smart tag to the term in the document
            context.PersistTag(propertyBag);

            // This implementation only finds the first instance of a 
            // smart tag term in the cell. 
            break;
        }
    }
}
Private Sub Recognize(ByVal text As String, 
    ByVal site As ISmartTagRecognizerSite, ByVal tokenList As ISmartTagTokenList, 
    ByVal context As SmartTagRecognizeContext) Implements ISmartTagExtension.Recognize

    ' Determine whether each smart tag term exists in the document text.
    Dim Term As String
    For Each Term In smartTagDemo.Terms

        ' Search the cell text for the first instance of 
        ' the current smart tag term.
        Dim index As Integer = context.CellText.IndexOf(Term, 0)

        If (index >= 0) Then

            ' Create a smart tag token and a property bag for the 
            ' recognized term.
            Dim propertyBag As ISmartTagProperties = site.GetNewPropertyBag()

            ' Write a new property value.
            Dim key As String = "Key1"
            propertyBag.Write(key, DateTime.Now)

            ' Attach the smart tag to the term in the document.
            context.PersistTag(propertyBag)

            ' This implementation only finds the first instance
            ' of a smart tag term in the cell. 
            Exit For
        End If
    Next
End Sub

Remarks

Call PersistTag from an implementation of the Recognize method to indicate that the smart tag was found in the text. Use the propertyBag parameter to commit any custom properties for the smart tag. You can use these properties to customize the action taken when an item from the smart tag shortcut menu is selected.

Applies to