How to: Create Yearly Recurrence

  • 2 minutes to read
<dxsch:SchedulerControl.AppointmentItems>
    <!--An appointment occurs every seventh day of February every year. Four occurrences.-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="Every seventh day of February every year. Four occurrences."
        RecurrenceInfo="{dxsch:RecurrenceYearly Start='1/1/2020 13:00:00', ByMonthDay=7, ByMonth=2, OccurrenceCount=4}" />
    <!--An appointment occurs the second Monday in August for 2 years. Infinite (no end date).-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="The second Monday in August with a 2-year interval. Infinite (no end date)."
        RecurrenceInfo="{dxsch:RecurrenceYearly Start='1/1/2020 13:00:00', ByMonth=8, ByDay=Monday, WeekOfMonth=Second, Interval=2}" />
    <!--An appointment occurs on the last day of every year for 10 years.-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="An appointment occurs on the last day of every year for 10 years."
        RecurrenceInfo="{dxsch:RecurrenceYearly Start='1/1/2020 13:00:00', End='1/1/2030 13:00:00', ByMonth=12, ByMonthDay=31}" />
</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 every seventh day of February every year. Four occurrences.
    AppointmentItem apt1 = CreateAppointmentPattern("Every seventh day of February every year. Four occurrences.", 5);
    apt1.SetRecurrenceInfo(RecurrenceBuilder.Yearly(apt1.Start, 4).ByMonthDay(2, 7).Build());
    scheduler.AppointmentItems.Add(apt1);

    // An appointment occurs the second Monday in August for 2 years. Infinite (no end date).
    AppointmentItem apt2 = CreateAppointmentPattern("The second Monday in August with a 2-year interval. Infinite (no end date).", 5);
    apt2.SetRecurrenceInfo(RecurrenceBuilder.Yearly(apt2.Start).ByMonthDay(8, WeekDays.Monday, WeekOfMonth.Second)
        .Interval(2).Build());
    scheduler.AppointmentItems.Add(apt2);

    // An appointment occurs on the last day of every year for 10 years.
    AppointmentItem apt3 = CreateAppointmentPattern("The last day of every year for 10 years.", 5);
    apt3.SetRecurrenceInfo(RecurrenceBuilder.Yearly(apt3.Start, apt3.Start.AddYears(10)).ByMonthDay(12, 31).Build());
    scheduler.AppointmentItems.Add(apt3);