Question

We are currently working on creating a sync service between our product and Exchange using Exchange Web Services Managed API. Specifically we want to sync (on a time schedule) specific Appointments back and forth on a users calender. As part of the sync, we don't necessarily want to sync ALL appointments, but have built up some complex SearchFilters to return only the appointments we want. Our problem is that in order to use the SearchFilters, we need to use the ExchangeService.FindItems method, but this method only returns the Master Recurrence of recurring events. Our other option is to use ExchangeService.FindAppointment, this will do the Recurrence Expansion for us, but has the new problem that we can only limit the result appointments using a start and end date. Looking at how the ExchangeService.FindAppointment is implemented, we can see that it is implemented using the FindItems method, which leads me to believe that I should be able to tell the ExchangeService.FindItems method to do a recurrence expansion.

How can I get a list of expanded appointments from exchange using a complex SearchFilter?

Was it helpful?

Solution

Just found this on MSDN: http://msdn.microsoft.com/en-us/library/hh148195(v=exchg.140).aspx

Considerations for searching calendar appointments

Calendar appointments are a special case for searches. Some calendar appointments, such as recurring appointments, can have exceptions and deleted occurrences. To ensure that the Exchange server expands recurring appointments when searching a calendar folder, you need to use calendar paging. When you use calendar paging, however, you can’t use any other search restrictions. This means that if, for example, you want to display all of the calendar appointments this month for a particular organizer, you can't create a search filter that is based on the organizer. Instead, you can use the CalendarView class to query for all appointments in the month and then filter the appointments on the client side based on the organizer. The following example shows how to use a calendar view to search for appointments in a calendar.

OTHER TIPS

For anyone that finds guxiyou's solution with FindAppointments/CalendarView impractical, my solution below. CalendarView is especially not convenient in a situation of automatic synchronization where you'd preferably use a "last modified" filter instead of retrieving everything and filtering client-side, which is not very performant.

I used the regular FindItems way which does support filters, and while iterating the appointments checked AppointmentType, which in case of a RecurrenceMaster type would find the linked occurrences and add these to the to-be-synced list.

Below the method to subsequently get the occurrences of these appointments. Recurrent patterns with no end date are ignored as these would make your loop infinite. These recurrences would have to be handled differently to be synchronized anyway, unless you limit the synchronization window.

    private IEnumerable<Appointment> GetRecurrentAppointments(Appointment masterAppointment)
    {
        Recurrence recurrence = masterAppointment.Recurrence;

        if (recurrence == null || !recurrence.HasEnd)
            yield break;

        for (int i = 1; i <= recurrence.NumberOfOccurrences; i++)
        {
            Appointment occurrence = Appointment.BindToOccurrence(ExchangeServiceProxy, masterAppointment.Id, i);

            yield return occurrence;
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top