in

Platinum Bay

Peace, Love, and...

This Blog

Syndication


.NETicated

Extending Outlook with VSTO SE

The Everywhere Platform

Other than Windows and its default applications such as Notepad and Internet Explorer, what one piece of software is on more desktops than any other? In most companies, the president, sales staff, support staff, office manager, and sometimes even the janitor have Microsoft Outlook installed. The question begs asking then, why do folks only think about email and their calendar when they think about Outlook? Part of the reason may lie in Outlook's COM underpinnings and the dissatisfaction of working with VBA.

While Outlook is still a COM based platform, key advances have made it much more accessible for developers. Since Outlook 2003, Microsoft has provided a set of extensibility tools called the Visual Studio Tools for Office (VSTO). With the release of Visual Studio 2008 and VSTO Second Edition, developers now have powerful tools such as graphical designers and code templates to interact with Outlook's extensibility model.

Outlook's History

In 1997, with the release of Exchange Server 5.5, Microsoft replaced the Exchange client with Outlook.

Outlook 97

version 8.0

Released January 16, 1997


Outlook 98

version 8.5

Released June 21, 1998


Outlook 2000

version 9.0

Released June 7, 1999

VBA, COM

Outlook 2002

version 10

Released May 31, 2001

VBA, COM, PIA

Office Outlook 2003

version 11

Released October 21, 2003

VBA, COM, PIA, VSTO

Office Outlook 2007

version 12

Released November 30, 2006

VBA, COM, PIA, VSTO SE

Table 1 - Source Wikipedia

Back then, the only way to interact with Outlook was through custom forms. Microsoft then added extensibility through VBA and COM. Oh, these were the days. Weak types and Object return types. Yum! Like ASP.OLD, we got real sick of this really quick.

PIA – Primary Interop Assemblies

Starting with Outlook 2002, Microsoft started supplying managed assemblies to allow managed code developers to work with Outlook a little easier, and while it did make life easier, it was still no picnic.

VSTO is Born

Beginning with Outlook 2003, Microsoft started shipping the Visual Studio Tools for Office. VSTO provided a wrapper around the PIAs, and made it easier to interact with the Outlook object model. Microsoft has since shipped VSTO Second Edition (SE) for Microsoft Office 2007.

Outlook 2007 Object Model

The Outlook object model is largely contained within two assemblies:

  • PIA – Microsoft.Office.Interop.Outlook.dll
  • VSTO – Microsoft.Office.Tools.Outlook.dll

To get started with the object model, you should be familiar with the following top-level classes:

  • Application
    Represents an Outlook application and is the highest-level class in the object model.
    • Explorer
      Explorer represents a window that displays the contents of a folder that contains items such as e-mail messages, tasks, or appointments.
    • Inspector
      Inspector represents a window that displays a single item such as an e-mail message, task, or appointment.
    • MAPIFolder
      The MAPIFolder class represents a folder that contains e-mail messages, contacts, tasks, and other items. Outlook provides 16 default MAPIFolder objects.
    • MailItem, AppointmentItem, TaskItem, ContacItem

You can view interactive diagrams of the complete object model on MSDN: Outlook Object Model Reference

VSTO SE and Visual Studio 2008

VSTO SE for Visual Studio 2008 adds some neat designer templates, such as Ribbon and Form.

Debugging Outlook Add-Ins

Here are a couple tips for debugging Outlook add-ins. First, create a separate profile in Outlook. Next, set up the Debug properties for your project to open Outlook, and pass the profile switch.

Lastly, there is a neat tool called OutlookSpy which can make Outlook debugging and development much easier.

Developing for Multiple Outlook Versions

One project is required for each version of Outlook you wish to target. An OO approach is best here; separate the business logic so it can be included in each project.

Building a Ribbon Add-In

Extending the Outlook ribbon is not unlike Windows Forms development. A ribbon view is displayed in the designer, and can be laid out using drag-and-drop. The designer hierarchy, and the underlying VSTO hierarchy is ribbon, tab, tab group, controls as seen in figure 1. The full range of controls can be found in the toolbox, including

The one caveat of ribbon customization is finding the correct tab or tab group ID. To help, Microsoft has a set of Excel files for download which contain these IDs. The download can be found here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=4329D9E9-4D11-46A5-898D-23E4F331E9AE&displaylang=en

After that, the rest is laying out the forms, and attaching to form elements and the Outlook object model.

Ribbon IntelliSense Hack

Note: In order to get Intellisense for the ribbon XML, copy the CustomUI file from
    C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\1033\CustomUI.xsd
to the Visual Studio schemas directory
    C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\

Building a Form Region Add-In

Form regions, though similar to the earlier custom forms, are considerably more powerful. Form regions can be added to any inspector window and can help supplement information for the inspector item such as an email or calendar event.

When adding a form region to a project, a wizard is displayed which provides options to create different types of form regions. You have the option to create a separate, adjoining or replacement region, or to replace all the regions in a given area. If you don't like the way the MailItem editor works, you could write your own by using the Replacement region option, and attaching your controls to the underlying object model.

Learning about VSTO and Outlook add-ins opens up a world of possibilities for custom productivity tools, legacy systems integration, and ISV products.

Published Jan 15 2008, 11:32 PM by Steve
Filed under: , ,

Comments

February 27, 2008 3:32 PM

Actually I have a question. I am using VS2008 VSTO 3.0

Is it possible in Outlook 2007 to add a custom folder at root level (At the same level of 'Personal Folders', 'Archive Folders' etc) ?

If yes, How ?

And then is it possible to add Outlook Form Region for the click of this custom folder.

I would really appreciate any help

Thank you very much

SynDev
 

September 20, 2008 10:05 AM

Create Post

Ion Singh
 

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews is an independent consultant, INETA speaker, and Microsoft MVP for Visual Studio ALM. He has been working in technology for over ten years focusing on custom application development and Application Lifecycle Management. Steve is also Microsoft and IBM certified and a community fanatic having led sessions at nearly 100 events across North America. When he's not developing software solutions or engaging with the community about software technology, Steve is a closet singer and songwriter and plays the guitar and keys. Occasionally, Steve even gets to sleep. Occasionally.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.