I mentioned synching my Outlook and Google Calendars. Instead of waiting for somebody to do it for me I’m going to start doing it myself. I’m not sure I’ll finish but hopefully I can save somebody time in the future and provide a Visual Studio/Outlook tutorial on the way. I plan on publishing all source code as I go to make it easier for download.
Main Goal: Synch Outlook and Google Calendars
- Goal 1: Enumerate Outlook Appointments
- Goal 2: Schedule Enumeration
- Goal 3: Enumerate Google Appointments
- Goal 4: Compare Appointment Lists in a unified format.
- Goal 5: Add and delete (Synchronize) appointments based on user settings.
To be able to access the Microsoft Office (2003) System through Visual Studio 2005 I needed VSTO, this is Visual Studio Tools for the Microsoft Office System or Visual Studio Tools for Office.
There are different VSTO packages and versions. I will not go into them. I do not because the whole thing confuses me.
Step 1: Install VSTO. Fortunately I had this CD through an MS partner program. However it will cost a few hundred dollars if you do not. You must have Office 2003 installed along with Office 2003 Service Pack 1. After installing the service pack, VSTO installed with no hitch although it was a pretty sluggish install.
Step 2: Learning the interface. Seeing as how Outlook will need to be open in order to enumerate the appointments, I have chosen to make an Outlook add-in. Fortunately I was able to find a few VSTO-Outlook Samples on Microsoft.com.
After installing VSTO, it is very easy to create a blank Outlook AddIn. Create a new project, choose either VB or C# (I use C#) and expand the list. Select “Office” and the “Outlook Add-in” Visual Studio installed templates as seen here.

After clicking ok to create the blank project, I took a look at the Solution Explorer. Right now there is only one file that I am interested in. The main guts of code go into “ThisApplication.cs”.
Opening ThisApplication.cs showes to methods already created. These are “ThisApplication_Startup” and “ThisApplication_Shutdown”. You’ve probably guessed that the first one is fired at startup and the second and shutdown.
For my first test I thought I would just show myself how many appointments I currently have in Outlook. Before I go into that the first thing that you should keep in mind is that Outlook is all about MAPI folders. MAPI (Messing API or Messaging Application Programming Interface) basically is the interface dealing with messages and message stores. It kind of should be called MS MAPI as I believe that Microsoft owns the interface/protocol. You can read more about MAPI here and here.
The reason that I point out MAPI folders is that it is a generic folder. Your inbox is a MAPI folder, so is your outbox, calendar, contacts etc… All MAPI folders are of the type “Outlook.MAPIFolder”. This struck me as odd and I struggled with accepting this. Initially I thought that each folder should be a different type. I thought the Inbox and Outbox should be of an email type because it contained emails while the calendar would be yet another type. However this is more similar to a directory structure than a class so it should make more sense as we go along.
So on to my first Outlook Add-in. All that I did was place the following 3 lines in the Startup method and ran the program. VS is smart enough to add and run the add-in. All that you need to be sure of is that Outlook isn’t currently open.
Outlook.MAPIFolder Calendar = this.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items Appointments = Calendar.Items;
MessageBox.Show(Appointments.Count.ToString());
Upon running Outlook you should see a popup message with a number in it telling you how many appointments are in your Calendar. It is kind of useless except to show you that it works. However we are close to actually detailing the appointments at this point.
The next step is to iterate through the items and put them into a class that will make it easier for us later on. I ended up saving these items into a class. This way when we load the information from our Google calendar we can do so to this class with no problems.
You can see the source code here that I have for ENUMERATE OUTLOOK APPOINTMENTS USING VSTO.
I will be working on Goal 2 when I need a break durning my normal work day.