Version

Delete a Recurring Appointment Server Side

Deleting a recurring appointment involves four steps:

  1. Retrieve a recurring Activity .

  2. Get the root activity of the Recurrence .

  3. Delete the recurrence.

  4. Update the database with any changes.

The first task in deleting a recurring appointment is to retrieve the activity that contains the recurring appointment. For the purposes of this topic, we will assume that there is a recurring appointment that occurs today. After you’ve retrieved the activity, you need to access the RootActivity for that recurrence (because recurrence objects are created from activities). Once you have a hold on the RootActivity, you can delete the recurrence by setting the RecurrenceKey to an empty string. Finish up by updating the database with your changes.

In Visual Basic:

Imports Infragistics.WebUI.Shared
Imports Infragistics.WebUI.WebSchedule
...
' Use the GetActivitiesForDate method to find an appointment
' that occurs today.
Me.WebScheduleInfo1.DataBind()
Dim activities As ActivitiesSubsetCollection = _
  Me.WebScheduleInfo1.GetActivitiesForDate(Me.WebScheduleInfo1.ActiveResource, _
  New SmartDate(DateTime.Now))
Dim appointment As Appointment = CType(activities(0), Appointment)
' Get the root activity of the recurrence.
appointment = CType(appointment.Recurrence.RootActivity, Appointment)
' The recurring appointment you're deleting.
appointment.Recurrence.MaxOccurrences = 5
' Delete the recurrence by setting the Key to an empty string.
appointment.RecurrenceKey = ""
' You need to call DataBind again to update the Activities collection.
' WebScheduleInfo will not automatically call it after you've already
' called it once.
Me.WebScheduleInfo1.DataBind()

In C#:

using Infragistics.WebUI.Shared;
using Infragistics.WebUI.WebSchedule;
...
// Use the following using directives so you don't have to
// type out the fully qualified name every time.
using Infragistics.WebUI;
using Infragistics.WebUI.WebSchedule;
// Use the GetActivitiesForDate method to find an appointment
// that occurs today.
this.WebScheduleInfo1.DataBind();
ActivitiesSubsetCollection activities =
  this.WebScheduleInfo1.GetActivitiesForDate(this.WebScheduleInfo1.ActiveResource,
  new SmartDate(DateTime.Now));
Appointment appointment = (Appointment)activities[0];
// Get the root activity of the recurrence.
appointment = (Appointment)appointment.Recurrence.RootActivity;
// The recurring appointment you're deleting.
appointment.Recurrence.MaxOccurrences = 5;
// Delete the recurrence by setting the Key to an empty string.
appointment.RecurrenceKey = "";
// You need to call DataBind again to update the Activities collection.
// WebScheduleInfo will not automatically call it after you've already
// called it once.
this.WebScheduleInfo1.DataBind();