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

How to: Create Weekly 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 recurs every 2 weeks, on Monday and Wednesday. It occurs 15 times.
    AppointmentItem apt1 = CreateAppointmentPattern("Every 2 weeks, on Monday and Wednesday, 15 times.", 3);
    apt1.RecurrenceInfo.Type = RecurrenceType.Weekly;
    apt1.RecurrenceInfo.Start = apt1.Start;
    apt1.RecurrenceInfo.Periodicity = 2;
    apt1.RecurrenceInfo.WeekDays = WeekDays.Monday | WeekDays.Wednesday;
    apt1.RecurrenceInfo.Range = RecurrenceRange.OccurrenceCount;
    apt1.RecurrenceInfo.OccurrenceCount = 15;
    scheduler.AppointmentItems.Add(apt1);

    // An appointment occurs every fourth week on weekends. Infinite (no end date).
    AppointmentItem apt2 = CreateAppointmentPattern("Every fourth week on weekends. Infinite (no end date).", 3);
    apt2.RecurrenceInfo.Type = RecurrenceType.Weekly;
    apt2.RecurrenceInfo.Start = apt2.Start;
    apt2.RecurrenceInfo.Periodicity = 4;
    apt2.RecurrenceInfo.WeekDays = WeekDays.WeekendDays;
    apt2.RecurrenceInfo.Range = RecurrenceRange.NoEndDate;
    scheduler.AppointmentItems.Add(apt2);

    // An appointment occurs every Friday for 24 days.
    AppointmentItem apt3 = CreateAppointmentPattern("Every Friday for 24 days.", 3);
    apt3.RecurrenceInfo.Type = RecurrenceType.Weekly;
    apt3.RecurrenceInfo.Start = apt3.Start;
    apt3.RecurrenceInfo.Periodicity = 1;
    apt3.RecurrenceInfo.WeekDays = WeekDays.Friday;
    apt3.RecurrenceInfo.Range = RecurrenceRange.EndByDate;
    apt3.RecurrenceInfo.End = apt3.RecurrenceInfo.Start.AddDays(24);

    scheduler.AppointmentItems.Add(apt3);