|
|
YOUR FEEDBACK |
TOP MICROSOFT .NET LINKS Feature
Synchronizing Multiple Exchange Calendars
Build an Outlook add-in that lets you synchronize your Exchange calendar across multiple Exchange servers
By: Jerry Brunning
Apr. 29, 2006 06:45 AM
Digg This!
Page 2 of 2
« previous page
Processing Calendar Events Using WebDav to talk to Exchange over HTTP can be a daunting task because of the complexity and amount of code required to handcraft the HTTP calls. Fortunately, there are third-party products that encapsulate this into simple object-oriented calls. One such product is IndependentSoft's WebDav .NET for Exchange (www.independentsoft.de/webdavex/index.html). WebDav .NET for Exchange is a managed assembly that exposes objects and methods for making calls to an Exchange server over WebDav. With WebDav .NET for Exchange, adding calendar items to a remote Exchange server is as easy as setting some properties and calling a method. Adding new calendar items is simple: Get the details of the new calendar item and create a new calendar entry on our target Exchange server with the same data (subject, start time, end time, etc.) using WebDav. In code, we do this using the ItemAddHandler that we set up earlier. Since WebDav .NET for Exchange expects an instance of an IndependentSoft appointment as a parameter and we're working with an instance of an Outlook appointment, we simply need to map the properties from the Outlook appointment to the IndependentSoft appointment (see Listing 3). Note that after each item is added to the remote Exchange server, we'll write an entry to a cache containing the calendar item's EntryID plus some other data about the appointment. We do this so we can permanently map the item on the "client" Exchange server to an item on the target Exchange server. We also persist the cache to a file so we have access to it next time we run Outlook. It's important to do this because without this cache we wouldn't be able to update the target server if a calendar item changes on the "client" Exchange server. Updating calendar items is a little more difficult because we have to map the changed item on our "client" Exchange server to an existing item on our target Exchange server. To do this we have to read from our cache to get a handle on the calendar item on the remote server. Once we have this, we can use WebDav to update the item on the remote server. We also have to update our cache to make sure it references any changes we made. Listing 4 shows the code for updating an existing calendar item. Deleting calendar items presents the biggest challenge in our add-in. The reason is that the deleted item handler exposed by Outlook doesn't pass the item that was deleted as a parameter. Because of this, there's really no good way to use the deleted item handler to track deleted calendar items. Instead we'll link the ItemAdd handler on the Deleted Items folder. This gets called when any item (not just calendar items) are added to the Deleted Items folder. We just have to add a check in our event handler to ignore items that aren't calendar items. Other than that, we can use the same logic that we used for updating calendar items: Search the local cache for a handle to the remote item and make a WebDav call to delete the remote item. All of this is show in Listing 5. These three functions make up the core logic of the entire add-in. As items are added, changed, or removed from the "client" Exchange server through Outlook, our code is triggered to add, change, or remove the item from the target Exchange server. Now the target Exchange server always contains up-to-date calendar information. With very little work, the functionality presented here can be extended to other Exchange items, such as e-mails and tasks. Adding additional features such as filtering which items are synchronized would be very easy.
Deploying Our Add-In
Conclusion Page 2 of 2 « previous page
MICROSOFT .NET LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING NEWS FROM THE WIRES
|
|||||||||||||||||||||||||||||||||||||||