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

How to: Create Daily 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 is set every 3 days. Five occurrences.
    AppointmentItem apt1 = CreateAppointmentPattern("Every 3 days. Five occurrences.", 2);
    apt1.RecurrenceInfo.Type = RecurrenceType.Daily;
    apt1.RecurrenceInfo.Start = apt1.Start;
    apt1.RecurrenceInfo.Periodicity = 3;
    apt1.RecurrenceInfo.Range = RecurrenceRange.OccurrenceCount;
    apt1.RecurrenceInfo.OccurrenceCount = 5;
    scheduler.AppointmentItems.Add(apt1);

    // An appointment is set every day. Infinite (no end date).
    AppointmentItem apt2 = CreateAppointmentPattern("Every day. Infinite (no end date).", 2);
    apt2.RecurrenceInfo.Type = RecurrenceType.Daily;
    apt2.RecurrenceInfo.Start = apt2.Start;
    apt2.RecurrenceInfo.Range = RecurrenceRange.NoEndDate;
    scheduler.AppointmentItems.Add(apt2);

    // An appointment occurs every five days. Appointments are set for one month.
    AppointmentItem apt3 = CreateAppointmentPattern("Every 5 days. Series for one month.", 2);
    apt3.RecurrenceInfo.Type = RecurrenceType.Daily;
    apt3.RecurrenceInfo.Start = apt3.Start;
    apt3.RecurrenceInfo.Periodicity = 5;
    apt3.RecurrenceInfo.Range = RecurrenceRange.EndByDate;
    apt3.RecurrenceInfo.End = apt3.RecurrenceInfo.Start.AddMonths(1);
    scheduler.AppointmentItems.Add(apt3);