Creating a Recurring Series
Creating a Recurring Series

Topic Last Modified: 2009-10-20

You can use the Microsoft Exchange Web Services (EWS) Managed API to create a recurring series of calendar items.

To create a recurring series

  1. Instantiate the Appointment object and identify the Exchange service. The following code shows how to create an appointment and provide it with connection configuration information by using an ExchangeService object named service.

    Appointment appointment = new Appointment(service);
    
  2. Set properties on the appointment and specify the recurrence pattern and recurrence range of the appointment. The following code shows how to add a subject, a body, a start time, an end time, and a location to an appointment, and how to specify that the appointment recurs every Saturday for ten weeks, effective January 1, 2009.

    appointment.Subject = "Weekly Tennis Lesson";
    appointment.Body = "My one hour tennis lesson is every Saturday at 10 A.M. for ten weeks.";
    appointment.Start = new DateTime(2009, 1, 1, 10, 0, 0);
    appointment.End = appointment.Start.AddHours(1);
    appointment.Location = "Redmond Pavillion";
    DayOfTheWeek[] days = new DayOfTheWeek[] { DayOfTheWeek.Saturday };
    appointment.Recurrence = new Recurrence.WeeklyPattern(appointment.Start.Date, 1, days);
    appointment.Recurrence.StartDate = appointment.Start.Date;
    appointment.Recurrence.NumberOfOccurrences = 10;
    
    
  3. Save the appointment. The following code shows how to save an appointment to the calendar. For information about the methods that you can use to save and send new meeting requests, see Creating Appointments and Meetings.

    appointment.Save();
    
Example

Creating a Series with Daily Recurrence

The following code example shows how to create a recurring meeting series and a recurring appointment series. The meeting recurs daily for two weeks, starting on January 1, 2009. The appointment recurs every third day starting on January 1, 2009, through March 31, 2009.

// Create the meeting. 
Appointment meeting = new Appointment(service);

// Set properties on the meeting.
meeting.Subject = "Daily Meeting";
meeting.Body = "This one hour meeting will recur daily for two weeks, starting on January 1, 2009.";
meeting.Start = new DateTime(2009, 1, 1, 10, 0, 0);
meeting.End = meeting.Start.AddHours(1);
meeting.Location = "Conf Room 1";
meeting.RequiredAttendees.Add("User1@contoso.com");

// Set the recurrence information on the meeting.
// The meeting will recur daily for two weeks, starting on January 1, 2009.
meeting.Recurrence = new Recurrence.DailyPattern(meeting.Start.Date, 1);
meeting.Recurrence.StartDate = meeting.Start.Date;
meeting.Recurrence.EndDate = (meeting.Start.Date).AddDays(13);

// Create the meeting and send the meeting invitation to attendees.
meeting.Save(SendInvitationsMode.SendOnlyToAll);

// Create the appointment. 
Appointment appointment = new Appointment(service);

// Set properties on the appointment.
appointment.Subject = "Appointment - Every Third Day";
appointment.Body = "This one hour appointment will recur every third day, starting on January 1, 2009, and continuing through March 31, 2009.";
appointment.Start = new DateTime(2009, 1, 1, 10, 0, 0);
appointment.End = appointment.Start.AddHours(1);

// Set the recurrence information on the appointment.
// The appointment will recur every third day, starting on Januray 1, 2009, and continuing through March 31, 2009.
appointment.Recurrence = new Recurrence.DailyPattern(appointment.Start.Date, 3);
appointment.Recurrence.StartDate = appointment.Start.Date;
appointment.Recurrence.EndDate = new DateTime(2009, 3, 31);

// Save the recurring series.
appointment.Save();

Creating a Series with Weekly Recurrence

The following code example shows how to create a recurring meeting series and a recurring appointment series. The meeting recurs every Monday, effective January 1, 2009, and continuing indefinitely. The appointment recurs on Monday and Wednesday of every second week effective January 1, 2009, through March 31, 2009.

// Create the meeting. 
Appointment meeting = new Appointment(service);

// Set properties on the meeting.
meeting.Subject = "Weekly Meeting on Monday";
meeting.Body = "This one hour meeting will recur every Monday, effective January 1, 2009, and continuing indefinitely.";
meeting.Start = new DateTime(2009, 1, 1, 10, 0, 0);
meeting.End = meeting.Start.AddHours(1);
meeting.Location = "Conf Room 1";
meeting.RequiredAttendees.Add("User1@contoso.com");

// Set the recurrence information on the meeting.
// The meeting will recur every Monday, effective January 1, 2009, and continuing indefinitely.
DayOfTheWeek[] days = new DayOfTheWeek[] { DayOfTheWeek.Monday };
meeting.Recurrence = new Recurrence.WeeklyPattern(meeting.Start.Date, 1, days);
meeting.Recurrence.StartDate = meeting.Start.Date;

// Create the meeting and send the meeting invitation to attendees.
meeting.Save(SendInvitationsMode.SendOnlyToAll);

// Create the appointment. 
Appointment appointment = new Appointment(service);

// Set properties on the appointment.
appointment.Subject = "Bi-Weekly Appointment (Monday, Wednesday)";
appointment.Body = "This one hour appointment will recur on Monday and Wednesday of every second week, effective January 1, 2009, through March 31, 2009.";
appointment.Start = new DateTime(2009, 1, 1, 10, 0, 0);
appointment.End = appointment.Start.AddHours(1);

// Set the recurrence information on the appointment.
// The appointment will recur on Monday and Wednesday of every second week, effective January 1, 2009, through March 31, 2009.
DayOfTheWeek[] days2 = new DayOfTheWeek[] { DayOfTheWeek.Monday, DayOfTheWeek.Wednesday };
appointment.Recurrence = new Recurrence.WeeklyPattern(appointment.Start.Date, 2, days2);
appointment.Recurrence.StartDate = appointment.Start.Date;
appointment.Recurrence.EndDate = new DateTime(2009, 3, 31);

// Save the recurring series.
appointment.Save();

Creating a Series with Monthly Recurrence

The following code example shows how to create a recurring meeting series and a recurring appointment series. The meeting recurs on the 15th of each month, effective January 1, 2009, and continuing indefinitely. The appointment recurs on the 20th of every third month, effective January 1, 2009 through December 31, 2009.

// Create the meeting. 
Appointment meeting = new Appointment(service);

// Set properties on the meeting.
meeting.Subject = "Monthly Meeting";
meeting.Body = "This one hour meeting will recur on the 15th of each month, effective January 1, 2009, and continuing indefinitely.";
meeting.Start = new DateTime(2009, 1, 1, 10, 0, 0);
meeting.End = meeting.Start.AddHours(1);
meeting.Location = "Conf Room 1";
meeting.RequiredAttendees.Add("User1@contoso.com");

// Set the recurrence information on the meeting.
// The meeting will recur on the 15th of each month, effective January 1, 2009, and continuing indefinitely.
meeting.Recurrence = new Recurrence.MonthlyPattern(meeting.Start.Date, 1, 15);
meeting.Recurrence.StartDate = meeting.Start.Date;
meeting.Recurrence.NeverEnds();

// Create the meeting and send the meeting invitation to attendees.
meeting.Save(SendInvitationsMode.SendOnlyToAll);

// Create the appointment. 
Appointment appointment = new Appointment(service);

// Set properties on the appointment.
appointment.Subject = "Quarterly Appointment";
appointment.Body = "This one hour appointment will recur on the 20th of every third month, effective January 1, 2009 through December 31, 2009.";
appointment.Start = new DateTime(2009, 1, 1, 10, 0, 0);
appointment.End = appointment.Start.AddHours(1);

// Set the recurrence information on the appointment.
// The appointment will recur on the 20th of every third month, effective January 1, 2009 through December 31, 2009.
appointment.Recurrence = new Recurrence.MonthlyPattern(appointment.Start.Date, 3, 20);
appointment.Recurrence.StartDate = appointment.Start.Date;
appointment.Recurrence.EndDate = new DateTime(2009, 12, 31);

// Save the recurring series.
appointment.Save();

Creating a Series with Relative Monthly Recurrence

The following code example shows how to create a recurring meeting series and a recurring appointment series. The meeting recurs on the third Monday of each month, effective January 1, 2009, and continuing indefinitely. The appointment recurs on the last Thursday of every second month, effective January 1, 2009 through December 31, 2009.

// Create the meeting. 
Appointment meeting = new Appointment(service);

// Set properties on the meeting.
meeting.Subject = "Monthly Meeting (third Monday)";
meeting.Body = "This one hour meeting will recur on the third Monday of each month, effective January 1, 2009, and continuing indefinitely.";
meeting.Start = new DateTime(2009, 1, 1, 10, 0, 0);
meeting.End = meeting.Start.AddHours(1);
meeting.Location = "Conf Room 1";
meeting.RequiredAttendees.Add("User1@contoso.com");

// Set the recurrence information on the meeting.
// The meeting will recur on the third Monday of each month, effective January 1, 2009, and continuing indefinitely.
meeting.Recurrence = new Recurrence.RelativeMonthlyPattern(meeting.Start.Date, 1, DayOfWeek.Monday, DayOfWeekIndex.Third);
meeting.Recurrence.StartDate = meeting.Start.Date;
meeting.Recurrence.NeverEnds();

// Create the meeting and send the meeting invitation to attendees.
meeting.Save(SendInvitationsMode.SendOnlyToAll);

// Create the appointment. 
Appointment appointment = new Appointment(service);

// Set properties on the appointment.
appointment.Subject = "Bi-Monthly Appointment (last Thursday)";
appointment.Body = "This one hour appointment will recur on the last Thursday of every second month, effective January 1, 2009, and continuing through December 31, 2009.";
appointment.Start = new DateTime(2009, 1, 1, 10, 0, 0);
appointment.End = appointment.Start.AddHours(1);

// Set the recurrence information on the appointment.
// The appointment will recur on the last Thursday of every second month, effective January 1, 2009, and continuing through December 31, 2009.
appointment.Recurrence = new Recurrence.RelativeMonthlyPattern(appointment.Start.Date, 2, DayOfWeek.Thursday, DayOfWeekIndex.Last);
appointment.Recurrence.StartDate = appointment.Start.Date;
appointment.Recurrence.EndDate = new DateTime(2009, 12, 31);

// Save the recurring series.
appointment.Save();

Creating a Series with Yearly Recurrence

The following code example shows how to create a recurring appointment series. The appointment recurs on November 15th of each year, starting on November 15, 2009, and continuing indefinitely.

// Create the appointment. 
Appointment appointment = new Appointment(service);

// Set properties on the appointment.
appointment.Subject = "Yearly Appointment";
appointment.Body = "This one hour appointment will recur each year on November 15th, starting on November 15, 2009, and continuing indefinitely.";
appointment.Start = new DateTime(2009, 11, 15, 10, 0, 0);
appointment.End = appointment.Start.AddHours(1);

// Set the recurrence information on the appointment.
// The appointment will recur each year on November 15th, starting on November 15, 2009, and continuing indefinitely.
appointment.Recurrence = new Recurrence.YearlyPattern(appointment.Start.Date, Month.November, 15);
appointment.Recurrence.StartDate = appointment.Start.Date;
appointment.Recurrence.NeverEnds();

// Save the recurring series.
appointment.Save();

Creating a Series with Relative Yearly Recurrence

The following code example shows how to create a recurring appointment series. The appointment recurs on the first Monday in November each year for five years, starting in November 2009.

// Create the appointment. 
Appointment appointment = new Appointment(service);

// Set properties on the appointment.
appointment.Subject = "Yearly Appointment";
appointment.Body = "This one hour appointment will recur on the first Monday in November each year for five years, starting in November 2009.";
appointment.Start = new DateTime(2009, 11, 1, 10, 0, 0);
appointment.End = appointment.Start.AddHours(1);

// Set the recurrence information on the appointment.
// The appointment will recur on the first Monday in November each year for five years, starting in November 2009.
appointment.Recurrence = new Recurrence.RelativeYearlyPattern(appointment.Start.Date, Month.November, DayOfWeek.Monday, DayOfWeekIndex.First);
appointment.Recurrence.StartDate = appointment.Start.Date;
appointment.Recurrence.NumberOfOccurrences = 5;

// Save the recurring series.
appointment.Save();

Robust Programming

  • Properly handle all errors.
  • Check user input.
  • Use Autodiscover.
Security

  • Use HTTP with SSL for all communication between client and server.
  • Protect user passwords.
  • Validate all user input.
See Also

Tasks

Accessing Calendar Items in a Recurring Series
Deleting a Recurring Series
Updating a Recurring Series
Modifying and Deleting Items in a Recurring Series

Concepts

Understanding a Recurring Series

Other Resources

Working with Recurring Calendar Items

© 2010 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View