Skip to main content

How to: Create Weekly Recurrence

  • 2 minutes to read
<dxsch:SchedulerControl.AppointmentItems>
    <!--An appointment recurs every 2 weeks on Wednesday. It occurs 15 times.-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="2 weeks interval, on Wednesday, 15 occurrences."
        RecurrenceInfo="{dxsch:RecurrenceWeekly Start='1/1/2020 13:00:00', ByDay=Wednesday, Interval=2, OccurrenceCount=15}" />
    <!--An appointment occurs every fourth week on weekends. Infinite (no end date).-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="An appointment occurs every fourth week on weekends. Infinite (no end date)."
        RecurrenceInfo="{dxsch:RecurrenceWeekly Start='1/1/2020 13:00:00', ByDay=WeekendDays, Interval=3}" />
    <!--An appointment occurs every Friday for 24 days.-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="An appointment occurs every Friday for 24 days."
        RecurrenceInfo="{dxsch:RecurrenceWeekly Start='1/1/2020 13:00:00', End='1/25/2020 13:00:00', ByDay=Friday}" />
</dxsch:SchedulerControl.AppointmentItems>
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("2 weeks interval, on Monday and Wednesday, 15 occurrences.", 3);
    apt1.SetRecurrenceInfo(RecurrenceBuilder.Weekly(apt1.Start, 15).ByDay(WeekDays.Monday | WeekDays.Wednesday).Interval(2).Build());
    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.SetRecurrenceInfo(RecurrenceBuilder.Weekly(apt2.Start).ByDay(WeekDays.WeekendDays).Interval(3).Build());
    scheduler.AppointmentItems.Add(apt2);

    // An appointment occurs every Friday for 24 days.
    AppointmentItem apt3 = CreateAppointmentPattern("Every Friday for 24 days.", 3);
    apt3.SetRecurrenceInfo(RecurrenceBuilder.Weekly(apt3.Start, apt3.Start.AddDays(24)).ByDay(WeekDays.Friday).Build());
    scheduler.AppointmentItems.Add(apt3);