Search code examples
c#exchangewebservicesexchange-server-2010ews-managed-api

Get recurrence pattern for appointment using EWS Managed API 1.2


I am looking for the correct way to get the recurrence pattern associated with an appointment using EWS Managed API 1.2. My code looks something like this:

FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, view);

foreach (Appointment appointment in findResults)
{
    appointment.Load();

    if (appointment.IsRecurring)
    {
        // What is the recurrence pattern???
    }
}

I can do a appointment.Recurrence.ToString() and I get back like Microsoft.Exchange.WebServices.Data.Recurrence+WeeklyPattern. Obviously I could parse that and determine the type, but that doesn't seem very clean. Is there a better way?

There is another post similar to this here - EWS: Accessing an appointments recurrence pattern but the solution does not seem complete.


Solution

  • here's a full list of the patterns. Cause of there is no Property you could as what pattern is in use, you will have to cast the recurrence to the pattern. in my project I solved this problem this way:

    Appointment app = Appointment.Bind(service,id);
    Recurrence.DailyPattern dp = app.Recurrence as Recurrence.DailyPattern;
    Recurrence.DailyRegenerationPattern drp = app.Recurrence as Recurrence.DailyRegenerationPattern;
    Recurrence.MonthlyPattern mp = app.Recurrence as Recurrence.MonthlyPattern;
    Recurrence.MonthlyRegenerationPattern mrp = app.Recurrence as Recurrence.MonthlyRegenerationPattern;
    Recurrence.RelativeMonthlyPattern rmp = app.Recurrence as Recurrence.RelativeMonthlyPattern;
    Recurrence.RelativeYearlyPattern ryp = app.Recurrence as Recurrence.RelativeYearlyPattern;
    Recurrence.WeeklyPattern wp = app.Recurrence as Recurrence.WeeklyPattern;
    Recurrence.WeeklyRegenerationPattern wrp = app.Recurrence as Recurrence.WeeklyRegenerationPattern;
    Recurrence.YearlyPattern yp = app.Recurrence as Recurrence.YearlyPattern;
    Recurrence.YearlyRegenerationPattern yrp = app.Recurrence as Recurrence.YearlyRegenerationPattern;
    
    if (dp != null)
    { 
    //Do something
    }
    else if (drp != null)
    {
    //Do something
    }
    else if (mp != null)
    {
    //Do something
    }
    else if (mrp != null)
    {
    //Do something
    }
    else if (rmp != null)
    {
    //Do something
    }
    else if (ryp != null)
    {
    //Do something
    }
    else if (wp != null)
    {
    //Do something
    }
    else if (wrp != null)
    {
    //Do something
    }
    else if (yp != null)
    {
    //Do something
    }
    else if (yrp != null)
    {
    //Do something
    }
    

    hope that helps you...