Bringing Outlook Contacts to life using Virtual Earth and VSTO 3.0

Late last year .Net Fx 3.5 and VS 2008 was released and part of this release was the Visual Studio Tools for Office 3.0 which enhance the Office development experience and also make it extremely trivial. One of my favorites as part of VSTO 3.0 is Outlook Form Regions which allows the developer to bring custom content into Outlook forms using Windows Forms controls within OFRs. The walk through I will tackle in this post is building an Outlook form region for outlook contact which maps the contact address on a Virtual Earth map in a hosted web browser control and it only actually takes a single line of code to enable this.

 

image Begin by creating a new Office project in Visual Studio 2008, notice the true multi-targeting capabilities are inherent with VS 2008. For our exercise, create a Outlook 2007 add-in. Next add a new item of the type Outlook Form Region (name it something like MapIt) to the project. This will kick off a wizard to walk through for designing the OFR. The step look like the following

image image image image

The last step defines the Outlook Items for which this form region is enabled and we have selected the Contact Item. Next in the designer drop a WebBrowser control into the form region and open the C# code file for the form region in VS. Locate the formRegionShowing method and add the following line of code

if (this.OutlookItem is Outlook.ContactItem)
{
    webBrowser1.Url = new Uri(String.Format("https://maps.live.com?q={0}", ((Outlook.ContactItem)this.OutlookItem).BusinessAddress));
}

You are set to run the application and see the code in action - this will launch outlook, switch to contacts and open one up. Click on the MapIt link in the ribbon.

 

Voila!