Skip to main content
A newer version of this page is available. .

How to: Create Monthly Recurrence

  • 2 minutes to read
public AppointmentItem CreateAppointmentPattern(string subj, int categoryId) {
    AppointmentItem apt = new AppointmentItem(AppointmentType.Pattern);
    apt.Start = DateTime.Today.AddHours(9);
    apt.End = apt.Start.AddMinutes(5);
    apt.Subject = subj;
    apt.LabelId = categoryId;
    return apt;
}
    // An appointment occurs on the 11th day of each month. Four occurrences.
    AppointmentItem apt1 = CreateAppointmentPattern("On 11th day of each month. Four occurrences.", 4);
    apt1.RecurrenceInfo.Type = RecurrenceType.Monthly;
    apt1.RecurrenceInfo.Start = apt1.Start;
    apt1.RecurrenceInfo.DayNumber = 11;
    apt1.RecurrenceInfo.WeekOfMonth = WeekOfMonth.None;
    apt1.RecurrenceInfo.Range = RecurrenceRange.OccurrenceCount;
    apt1.RecurrenceInfo.OccurrenceCount = 4;
    scheduler.AppointmentItems.Add(apt1);

    // An appointment occurs on the last Wednesday of the month, for 2 months. Infinite (no end date).
    AppointmentItem apt2 = CreateAppointmentPattern("Last Wednesday of the month, for 2 months. Infinite (no end date).", 4);
    apt2.RecurrenceInfo.Type = RecurrenceType.Monthly;
    apt2.RecurrenceInfo.Periodicity = 2;
    apt2.RecurrenceInfo.Start = apt2.Start;
    apt2.RecurrenceInfo.WeekOfMonth = WeekOfMonth.Last;
    apt2.RecurrenceInfo.WeekDays = WeekDays.Wednesday;
    apt2.RecurrenceInfo.Range = RecurrenceRange.NoEndDate;
    scheduler.AppointmentItems.Add(apt2);

    // An appointment occurs on the first Monday of the month for 3 months. The series duration is one year.
    AppointmentItem apt3 = CreateAppointmentPattern("First Monday of the month for 3 months. The series duration is one year.", 4);
    apt3.RecurrenceInfo.Type = RecurrenceType.Monthly;
    apt3.RecurrenceInfo.Periodicity = 3;
    apt3.RecurrenceInfo.Start = apt3.Start;
    apt3.RecurrenceInfo.WeekOfMonth = WeekOfMonth.First;
    apt3.RecurrenceInfo.WeekDays = WeekDays.Monday;
    apt3.RecurrenceInfo.Range = RecurrenceRange.EndByDate;
    apt3.RecurrenceInfo.End = apt3.RecurrenceInfo.Start.AddYears(1);
    scheduler.AppointmentItems.Add(apt3);