Microsoft Outlook 2010 introduces a new user interface element called the Contact Card. The Contact Card exposes a context menu that you can use to add your own menu items. This Visual How To explains how to create an add-in by using Visual Studio Tools for Office 2010 to customize the Contact Card context menu.
This Visual How To shows how to add a menu item to the Contact Card context menu. Choosing the menu item displays the SMTP address of the selected contact.
You can use a Visual Studio Tools for Office add-in to run your compiled code inside Outlook and to interact with the Outlook object model.
To create the add-in
In Visual Studio 2010, create an add-in for Outlook 2010. Name the new project ExtendCC.
In the Solution Explorer window, right-click the project, select Add from the context menu, and then click New Item. In the Add New Item dialog box, Common Items, select Office, and then select Ribbon (XML).
Change the Name to ContactCardContextMenu and then click Add. Visual Studio adds two files; a source file and an XML file.
To customize the Microsoft Office Fluent UI context menu, you must use a Ribbon (XML) type, which requires an XML file that describes the user interface elements and a source file that contains your code.
To customize the context menu item
First, change the existing xmlns value in the XML file to the following value.
You must modify the existing GetCustomUI method so that it passes your XML to Outlook 2010 when Outlook 2010 asks for customizations to the Contact Card context menu.
To display your customization in Outlook
Modify the GetCustomUI method to be more specific about requests for the context menu XML.
At this point, you can add your custom method. In this example, you access the current contact and try to determine the contact's SMTP address.
To call your custom method
Next, add a method to try to find the contact's SMTP address by using the IMsoContactCard object.
Note
The IMsoContactCard object is defined in the primary interop assembly, Office.dll, of the Microsoft Office object library, not in Outlook 2010. Visual Studio Tools for Office automatically references the assembly for you.
TryDim card As Office.IMsoContactCard =
TryCast(control.Context, Office.IMsoContactCard)
If card IsNotNothingThen
MsgBox(GetSmtpAddress(card))
Else
MsgBox("Unable to access contact card")
EndIfCatch ex As Exception
MsgBox(ex.Message)
EndTry
Finally, add code in the ThisAddIn class to enable Outlook to load your code.