Overview of Smart Tag Development [Office 2003 SDK Documentation]

Knowledge workers use a variety of applications to manage data. Whether the primary purpose of these applications is communicating, analyzing, or describing data, the types of data that are involved are very similar.

Smart tags were first introduced in Microsoft® Office XP and are supported in Microsoft Word 2002, Microsoft Excel 2002, and to a limited extent in Microsoft Outlook 2002 (when Word is used as the Outlook e-mail editor or when reading HTML e-mail messages). There was also support for exposing smart tag actions within Microsoft Internet Explorer, so that documents created with Office applications will retain their smart tags when viewed as a Web page.

With the release of Microsoft Office 2003, smart tag support has been extended to Microsoft PowerPoint® 2003 and Microsoft Access 2003. In addition, the Office 2003 Research task pane and Persona Menu features that are available in Office applications support smart tags. Office 2003 also adds enhancements and improvements to smart tags based on feedback from users and developers.

Most knowledge workers use a limited set of types of data or information such as names, addresses, dates, or telephone numbers. Smart tags provide a way to link specified types of data across applications.

For example, let's examine a scenario where a manager is creating a list of employee names in a Microsoft Office Word 2003 report, and in an Office Excel 2003 spreadsheet. The employee names also appear in the same format in Microsoft Office Outlook® 2003. Without smart tags, this identical information is just data (a "string"), and these applications will process the data only in the context of the particular tasks that the applications were designed to perform. If the manager needs more information about an employee mentioned in a Word 2003 report, she has to launch a separate application to complete this simple task. The smart tag infrastructure can change this workflow by adding intelligence to data strings that you use in your Office applications.

A smart tag is a string with type information attached to it. With smart tags, the manager in the previous example can use the smart tag intelligence of Office applications to provide a list of intuitive actions for a string that is typed as a "person's name." From that list, the manager can select the most appropriate action. The actions include sending an e-mail message, scheduling a meeting , and getting the telephone number or other personal records of the employee.

Smart tags enable the dynamic recognition of terms within documents, making data in Office documents more meaningful and easier to act on. As a user enters information in an application that supports smart tags, strings of certain types are dynamically recognized and automatically tagged as the document is created. Once a term is recognized, the user can invoke an action from a list associated with that particular smart tag. For example, the user can insert relevant data, link to a Web page, look up data in a database, convert data to another format, and so on.

Developers can supply logic and a set of consistent actions for data by defining a common interface for annotating data within documents, and providing a standard architecture for associating actions with this annotated data. To make a software development analogy, you can think of smart tags as making tasks "object-oriented," rather than "application-oriented."

You can extend the capabilities of applications that support smart tags by developing smart tag "recognizers" that identify strings of one or more specific types (for instance, a book title, chemical formula, or case number). These recognizers communicate with an application that supports smart tags to identify the text that a user entered. Recognizers then apply a recognition algorithm on the text and communicate the identity of recognized strings to the application.

Smart tags save users time and effort by streamlining tasks that are currently performed with complicated manual procedures. With the current smart tag support in Word, Excel, PowerPoint, and Access, users do not need to launch multiple applications to accomplish a simple task or spend time searching the Web to find a specified Web site. Users can be taken where they want to go from within their Office application and be conveniently linked to critical internal corporate resources. The benefits that can be achieved with smart tag technology are wide and far-reaching.

Methods for Developing Smart Tags

There are two main ways you can develop smart tags.

1. Without Writing Code

If you don't want to write any code, you can build simple smart tag using Microsoft Office Smart Tag List (MOSTL) which is an XML-based smart tag list. It is the easiest and quickest way to develop a smart tag. Smart tag lists are not as flexible or powerful as smart tags implemented using a programming language, but they are great for the recognition of a somewhat restricted list of words, terms or phrases. Using smart tag list is a very convenient way to add a well-defined list of terms to be recognized.

Office 2003 added support to the MOSTL tool allowing search patterns to be used in addition to search lists. These search patterns are defined through regular expressions (RegEx) and context free grammar (CFG) . RegEx and CFGs are a powerful form of wildcard search.

For detailed information on how to create smart tags using the MOSTL tool, including step-by-step walkthroughs on how to create a smart tag list, see the "Microsoft Office Smart Tag List" section.

2. Using Programming Language

You can build custom smart tags using any programming language that can create a Component Object Model (COM) add-in. A smart tag dynamic-link library (DLL) is a COM DLL with applications that support smart tags functioning as hosts in Office 2003.

If you want to build a smart tag recognizer for use in Office 2003, at the very minimum, you have to implement the ISmartTagRecognizer interface. It is not necessary to implement the ISmartTagRecognizer2 interface if you don't need any of the functionality exposed by it. Similarly, to build a smart tag action for use in Office 2003, at the very minimum, you have to implement the ISmartTagAction interface. Again, it is not necessary to implement the ISmartTagAction2 interface if you don't need any of the functionality exposed by it.

Note  If you are building a smart tag specifically for Access only and no other application, you won't need to implement the ISmartTagRecognizer or ISmartTagRecognizer2 interfaces since Access does not support dynamic recognition. You only need to implement the ISmartTagAction interface and if you want to leverage the new functionality introduced in Office 2003, you can also additionally implement the ISmartTagAction2 interface.

You can create custom smart tags in either unmanaged or managed code. in Office 2003, there is managed code support for smart tag unlike in Office XP. If you have developed managed smart tag in Office XP, you would know that managed smart tags have to be registered for COM Interop at HKEY_CLASSES_ROOT and subjected to Office XP security checking. In addition, to deploy managed smart tag securely in Office XP, you would need to incorporate an unmanaged proxy known as shim to your managed smart tag project.

With the .NET support for managed smart tags in Office 2003, managed smart tags won't need to be registered for COM Interop in HKEY_CLASSES_ROOT and won't be subjected to Office 2003 security checking. Managed smart tag will be subjected to .NET security checks instead. In Office 2003, using the managed code loader is the recommended .NET way to load managed smart tag.

Note  The step-by-step Visual Basic .NET and Visual C# tutorials explain in detail how to do this. For a detailed discussion about the new .NET support for managed smart tag in Office 2003, see the "Managed Smart Tag .NET Support In Office 2003" topic.

You don't have to implement the version 2 smart tag APIs to be able to leverage the new .NET support for managed smart tags. But if you want to implement the ISmartTagRecognizer2 and ISmartTagAction2 interfaces as well, it is also fine as you can leverage the new .NET support for managed smart tags either way.

There is also a rich smart tag object model that you can plug into in Visual Basic for Applications (VBA). See the application specific VBA documentation included in Office 2003 for details.

Development Guidelines

There are a number of issues that developers should be aware of when developing custom smart tag recognizers and actions. Smart tag plug-ins — especially recognizer plug-ins — can adversely affect their host application if they are not written correctly. Successful development includes taking into consideration the stability of DLLs in Office applications, their robustness, and issues of forward compatibility.

  • Developers should not show a user interface directly from recognizer DLLs (for example by doing, frmVBSample.Show vbModal), since there could be cross-thread synchronization issues with DLLs that show a user interface in a background thread. For example, showing a user interface promotes a thread's priority, and if a thread's priority is boosted, it might cause unexpected behavior later in the application session of Word, Excel, PowerPoint and Access.
  • Developers should not work as if Excel, Word, PowerPoint and Access are the only client applications. For example, code that assumes that the host application is either Excel, Word, PowerPoint or Access may break when other applications support smart tags. In anticipation, the DLLs should be coded to fail gracefully if they are dependent on certain applications for functionality.
  • The XML property that is passed in through ISmartTagAction::InvokeVerb and ISmartTagAction2::InvokeVerb2calls is designed to ensure smart tag representation is consistent among various applications. This enables developers to obtain information about a smart tag without needing to write application specific code.

Smart Tag Add-in Development

Smart tag add-in development should be familiar to any developer who has worked with developing COM add-ins. Like COM add-ins, implementing a smart tag action provider or recognizer involves implementing a specific interface with the development tool of your choice.

A Word range, an Excel cell, a PowerPoint range, and Access control can have multiple smart tags assigned to it. For example, a cell could be a "StreetName" and an "Address" at the same time. Every smart tag has a type. Each smart tag type has one or more verbs defined for it, and each verb can have a different COM action handler.

In order to understand how recognition engines work with action add-ins, it is crucial to first understand the notion of a smart tag type.