| By Jerry Brunning | Article Rating: |
|
| April 29, 2006 06:45 AM EDT | Reads: |
26,911 |
Managing calendars across multiple Microsoft Exchange servers has always been a problem for those of us in consulting or other professional service fields. Having to aggregate appointments across calendars maintained at multiple client sites, plus your calendar back at the home office - and potentially even an Exchange calendar at home - is particularly cumbersome. Manually consolidating your calendars is time-consuming and error-prone - it only takes a couple of missed or double-booked appointments before you realize that there has to be a better way.
In this article we'll show you how to use Visual Studio 2005 Tools for the Microsoft Office System (VSTO) to write a Microsoft Outlook add-in that automatically aggregates free/busy information across multiple Exchange servers. In doing so we'll dig into the details of the much improved event model exposed by VSTO for integrating with the Office suite of applications. The new simplified add-in interface is much more reliable than the old IDTExtensibility2 interface and greatly reduces the time it takes to get your application off the ground. We'll also discuss how VSTO together with the Visual Studio 2005 IDE make coding and debugging your Outlook application a breeze. Finally, no discussion of Outlook add-ins would be complete without addressing deployment: getting your add-in into the hands of end users. We'll explore the tools and techniques (as well as a few gotchas) that you need to know to distribute your completed application.
What Is VSTO?
VSTO is a developer's toolkit providing a simplified interface, a built-in "AddInLoader" component, and integrated debugging capabilities that make writing Office add-ins as easy as writing Windows Form applications. Visual Studio 2005 and VSTO make it easier than ever for developers to build managed applications that integrate with and extend the Microsoft Office suite. While VSTO offers benefits for developers targeting most of the applications in the Microsoft Office suite, this article will focus only on building add-ins for Outlook. However, there are quite a few articles and samples on programming Word, Excel, and other Office products on the Visual Studio Tools for Office web portal at http://msdn.microsoft.com/office/understanding/vsto/.
Microsoft did a great job of focusing VSTO on the areas of Outlook extensibility that needed it the most: Tighter integration with Visual Studio, a simplified integration interface, better debugging capabilities, and easier deployment. VSTO offers all these things.
Integration with Visual Studio
With VSTO, starting an Outlook add-in project is easier than ever. VSTO introduces a series of new project types for creating projects that extend Microsoft Office. These include project templates for creating Excel workbooks, Word documents, and Outlook add-ins (see Figure 1). Selecting the project type of Outlook add-in will create a shell project for your add-in, plus a setup project for deployment. You're then ready to code your add-in.
Simplified Interface
In past versions of Visual Studio, the interface IDTExtensibility2 was the proper way to hook into Outlook and get at the Outlook object model. VSTO replaces the IDTExtensibility2 interface for a much simpler approach - the IStartup interface. IStartup exposes just two very clearly named events: Startup() and Shutdown(). When you start a new project using the Outlook add-in template, Visual Studio inserts event handlers for these two events as follows:
Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Private Sub ThisApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
Contrast these with the five ambiguous events exposed by IDTExtensibility2, OnConnection, OnAddInsUpdate, OnStartupComplete, OnBeginShutdown, and OnDisconnection. If you ever wrote an add-in using IDTExtensibility2, you know that the events did not regularly fire, and it wasn't clear by the event name when exactly you should expect the event to fire, or even what you should do in the event handler. As we'll see below, all of this is much easier with IStartup's two simple events.
Improved Debugging
VSTO handles all of the plumbing to hook into Outlook and gives you "F5 debugging" of Outlook add-ins. What this means is that you simply write your code and press F5 to run. VSTO will automatically start up Outlook, hook up your add-in, and start executing your code. You'll get all of the rich debugging features of the Visual Studio IDE (break points, watches, call stacks, etc.) without having to do anything different than you'd do with any other Visual Studio project.
As a developer, you're completely shielded from the underlying complexity of loading your managed add-in into Outlook's unmanaged address space. You don't need to worry about COM+ bridges, shims, or any other techniques thanks to VSTO's new AddInLoader component. The AddinLoader is the VSTO component for loading and unloading managed add-ins to and from Outlook's address space.
The AddinLoader does the following tasks:
- Sets up a dedicated AppDomain for your add-in. Because your add-in runs in its own AppDomain, it's isolated from other add-ins and from the VSTO runtime itself.
- Checks permissions (using Code Access Security) on the add-in assembly to ensure it has FullTrust permission. If not, the AddinLoader won't load the add-in.
- Proxies the calls from the IDTExtensibility2 interface to the IStartup interface.
To run the sample code included with this article, you'll have to install VSTO. If you have an MSDN subscription, you can download a copy of VSTO. You can also download a trial copy of VSTO from Microsoft at http://msdn.microsoft.com/vstudio/products/trial/.
Synchronizing Exchange Calendars
If you use more than one Exchange account you probably already know how difficult it can be to coordinate updates to multiple calendars. For example, you may have an Exchange account at a client and an Exchange account at your home office. With multiple calendars, ensuring that you have a single place to go to check your agenda can be tricky. Let's see if we can use VSTO and Visual Studio 2005 to solve this problem.
Using VSTO we can build an add-in that hooks into the Outlook object model and listens for calendar events. This allows us to detect changes to our calendar from one Exchange account - we just need a way to push the changes to the calendar in our second Exchange account. To do that we'll use WebDav, a set of HTTP extensions that we can use to interact with an Exchange account on a remote server.
So our scenario looks like this: We have our home office Exchange account and our "client" Exchange account. The goal is to make sure the home office Exchange account accurately reflects any calendar items that exist on either Exchange account. To do this we'll install an add-in on the "client" Exchange account that listens for changes to its calendar and then pushes those changes to the home office Exchange server using WebDav.
Getting Started
As mentioned above, starting an Outlook add-in project is pretty straightforward. Simply fire up Visual Studio, start a new project, and choose "Outlook add-in" as the project type from the Office project templates. Visual Studio creates the shell for your add-in and automatically adds event handlers for both the Startup() and Shutdown() events. Visual Studio also creates a setup project for your add-in. The setup project builds a Windows installer file (.MSI) and makes deploying your add-in easier.
The Startup() event is used to initialize your add-in. It's called whenever your add-in is loaded into memory. For our add-in we'll do three things during startup:
- Create an instance of our Calendar-Processing class. This is the main class that handles all of the logic for processing and synchronizing calendar entries.
- Create an instance of our Settings class. This is the class that stores all of the configuration settings for the add-in.
- Add a menu item to the Outlook toolbar. The menu item is used to pop up the settings screen.
Published April 29, 2006 Reads 26,911
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Jerry Brunning
Jerry Brunning is a partner at Clarity Consulting, a Chicago-based software development and consulting firm. He joined Clarity in April 1997. Since then he has served as the lead architect for numerous transactional client/server and Internet enabled solutions. Jerry's experience spans vertical markets such as finance/brokerage, e-commerce, insurance, pharmaceuticals, and telecommunications.
![]() |
Jim Underwood 05/22/08 12:14:42 AM EDT | |||
Jerry, Thanks for posting the file. Could you possible provide some instructions on how to use with Outlook? Is the Outlook compiled add-in in the zip file? Thanks, |
||||
![]() |
Jerry Brunning 05/21/08 07:26:57 PM EDT | |||
Sorry, there was a trailing space on the url in the prior post. The correct URL is http://employees.claritycon.com/jbrunning/Clarity.OutlookAddins.zip |
||||
![]() |
jim toner 05/21/08 07:13:02 PM EDT | |||
Hi Jerry the link does not work. Is there a place to get the source code. Jim |
||||
![]() |
Jerry Brunning 04/10/08 07:55:52 PM EDT | |||
The code for the addin can be found at http://employees.claritycon.com/jbrunning/Clarity.OutlookAddins.zip. I compiled the code using VS.Net 2008. I haven't run the code for a long time, so there may be some issues that you'll need to work through. I can try to help via email if anyone runs into problems, but I may not be very responsive to email for questions about this, as it is several years ago now since I've looked at it. |
||||
![]() |
Jerry Brunning 04/10/08 07:19:31 PM EDT | |||
Yes, I'll pull the code together tonight and post it somewhere. I'll follow up once I've done that. |
||||
![]() |
Jim Underwood 03/28/08 09:54:08 PM EDT | |||
Jerry, we would be most interested in installing/running the finished Outlook Add-in. I'm sure many, many others would be as well. Do you have the executable available for sale? |
||||
![]() |
Steve Smith 05/17/06 11:55:54 AM EDT | |||
Excellent article. |
||||
![]() |
Jon Cooper 04/28/06 01:48:02 PM EDT | |||
Great article! Is there any way that you could post the source and/or the compiled application? |
||||
![]() |
SYS-CON Australia News Desk 04/11/06 11:14:57 AM EDT | |||
Managing calendars across multiple Microsoft Exchange servers has always been a problem for those of us in consulting or other professional service fields. Having to aggregate appointments across calendars maintained at multiple client sites, plus your calendar back at the home office - and potentially even an Exchange calendar at home - is particularly cumbersome. Manually consolidating your calendars is time-consuming and error-prone - it only takes a couple of missed or double-booked appointments before you realize that there has to be a better way. |
||||
- iPad3 vs Windows 8 - and the Winner Is...Cloud
- Cisco Unveils Visual Collaboration Solutions in the Post-PC Era, Extending the Reach of TelePresence With New Mobile-to-Immersive Offerings
- Eleven Reasons Why Windows Phone Will Overtake Android
- Windows Azure Overview Part 4: Security
- Agile Development & Enterprise Architecture Practice – Can They Coexist?
- Eleven Tips for Successful Cloud Computing Adoption
- System Center Virtual Machine Manager 2012 as Private Cloud Enabler
- Apply Agile When Deploying Apps
- The Web – Changing the Way We Work
- EE Times and EDN Announce the 2012 UBM Electronics ACE Award Winners
- User Group Malaise?
- Closer Look at One NoSQL Database – MongoDB
- iPad3 vs Windows 8 - and the Winner Is...Cloud
- Cisco Unveils Visual Collaboration Solutions in the Post-PC Era, Extending the Reach of TelePresence With New Mobile-to-Immersive Offerings
- Eleven Reasons Why Windows Phone Will Overtake Android
- Windows Azure Overview Part 4: Security
- Agile Development & Enterprise Architecture Practice – Can They Coexist?
- Eleven Tips for Successful Cloud Computing Adoption
- System Center Virtual Machine Manager 2012 as Private Cloud Enabler
- Apply Agile When Deploying Apps
- The Web – Changing the Way We Work
- Book Review: Decision Management Systems
- EE Times and EDN Announce the 2012 UBM Electronics ACE Award Winners
- User Group Malaise?
- Google Maps and ASP.NET
- Converting VB6 to VB.NET, Part I
- How to Write High-Performance C# Code
- Crystal Reports XI & How It Has Changed
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- Programmatically Posting Data to ASP .NET Web Applications
- Implementing Tab Navigation with ASP.NET 2.0
- AJAX World RIA Conference & Expo Kicks Off in New York City
- i-Technology Viewpoint: "SOA Sucks"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"























