In this blog post I’ll demonstrate how you can use Exchange Web Services (EWS) via the EWS Managed API to access an Exchange Mailbox calendar and view any appointments that are Online Lync meetings and access information associated with this appointment type. The working examples I’ll show are written to work against Exchange Online and Lync Online from the Office365 suite but they are also valid to use within a private cloud or on-premise deployment of Lync 2010 and Exchange 2010.
When a user schedules an Online meeting in Outlook 2010 the Lync specific information associated with that appointment gets stored in a number of MAPI properties on the Appointment Item. Below is example of these Mapi properties on an Appointment Item as viewed in a Mapi Editor
To access this information in the EWS Managed API requires the use of Extended Properties which allows you to access the underlying Mapi properties of any Item in the Exchange Store that you access via EWS.
Working with Calendar Data in EWS
To make this information a little more meaningful I’ll go through step by step the code you would need to write to access an Exchange Online Users Calendar, retrieve the appointments for the next month and filter and display the Lync specific appointments.
Step 1 – Working out the EWS Connection details
The first step when writing any EWS Managed API code is you need to work out the details of the Client Access Server (CAS) that your requests are going to be sent through. Exchange
provides the ability to find the most appropriate CAS server to use via the use of Autodiscover. Programmatically with Exchange Online the following code provides the most efficient way of getting the URL to CAS server for EWS.
Step 2 - Connecting to the Server
Once you have the Url of the CAS server to connect to you are then ready to connect to the mailbox. In regards to authentication with the credentials that you are going to use to access the calendar if you are accessing a calendar other than the mailbox those credentials are associated with you have the following two authentication options. EWS Impersonation allows you to have a single service account that will then connect to a number of calendars while impersonating the owner of these calendars. Delegate access where the user has been granted specific rights to those calendars they are accessing. This example will use Delegate access. The following code fragment demonstrates how to connect to exchange and specify the user’s calendar folder you wish to access
Step 3 – Retrieving Calendar Appointments for the next month
To get the Exchange Server to return the Appointments the owner has scheduled for the next month in EWS you use a FindItems operation with Calendar Paging. Using Calendar paging means you’re telling EWS you want it to expand any reoccurring Appointments in the calendar because in the Exchange Store reoccurring appointments are only represented by one object with the recurrence pattern stored in a property. One of limitations of using Calendar paging is that you
can’t use this in conjunction with a SearchFilter (Restriction) that would limit the results return based on a particular property of an Item (in this case where it’s an online appointment). What this means is that to do the final filtering of appointments you need to do some client side logic. The other thing to note when you’re using FindItems is that this operation only returns a subset of properties on an Appointment, properties such as attendees need to be loaded using a separate GetItem operation. In the example below I’ve used the Managed API’s LoadPropertiesForItems method which does a batch Get Items operation on all the Items for which you wish to retrieve the requested properties on. The Following example shows how to retrieve all the calendar appointments for the next month and filter out those that are Online Lync Meetings the results are then stored in Datatable which then could be bound to datagrid etc …
Glen Scales is a freelance software developer and engineer based in Sydney, Australia who specializes in using Microsoft Exchange APIs to create customized solutions for a range of clients and industries, particularly in the realm of cloud-based services within messaging environments. He has been an Exchange MVP since 2004, contributing regularly to the Exchange development forums on TechNet and creating and sharing open source code libraries and scripts on his blog (http://gsexdev.blogspot.com)
You can also follow him on twitter via @glenscales
The MVP Monday Series is created by Melissa Travers. In this series we work to provide our readers with a guest post from one of our MVPs every Monday. Melissa is a Community Program Manager for Dynamics, Excel, Office 365, Platforms and SharePoint in the United States. She has been working with MVPs since her early days as Microsoft Exchange Support Engineer when MVPs would answer all the questions in the old newsgroups before she could get to them.