Skip to main content

How to: Create Monthly Recurrence

  • 3 minutes to read
<dxsch:SchedulerControl.AppointmentItems>
    <!--An appointment occurs on the 11th day of each month. Four occurrences.-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="On 11th day of each month. Four occurrences."
        RecurrenceInfo="{dxsch:RecurrenceMonthly Start='1/1/2020 13:00:00', ByMonthDay=11, OccurrenceCount=4}" />
    <!--An appointment occurs on the last Wednesday of the month, for 2 months. Infinite (no end date).-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="Last Wednesday of the month, for 2 months. Infinite (no end date)."
        RecurrenceInfo="{dxsch:RecurrenceMonthly Start='1/1/2020 13:00:00', ByDay=Wednesday, WeekOfMonth=Last, Interval=2}" />
    <!--An appointment occurs on the first Monday of the month for 3 months. The series duration is one year.-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="First Monday of the month for 3 months. The series duration is one year."
        RecurrenceInfo="{dxsch:RecurrenceMonthly Start='1/1/2020 13:00:00', ByDay=Monday, WeekOfMonth=First, Interval=3, End='1/1/2021 13:00:00'}" />
</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 occurs on the 11th day of each month. Four occurrences.
    AppointmentItem apt1 = CreateAppointmentPattern("On 11th day of each month. Four occurrences.", 4);
    apt1.SetRecurrenceInfo(RecurrenceBuilder.Monthly(apt1.Start, 4).ByDay(11).Build());
    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.SetRecurrenceInfo(RecurrenceBuilder.Monthly(apt2.Start).ByDay(WeekDays.Wednesday, WeekOfMonth.Last)
        .Interval(2).Build());
    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.SetRecurrenceInfo(RecurrenceBuilder.Monthly(apt3.Start, apt3.Start.AddYears(1))
        .ByDay(WeekDays.Monday, WeekOfMonth.First).Interval(3).Build());
    scheduler.AppointmentItems.Add(apt3);