Platform SDK: Exchange 2000 Server

Canceling Recurring Appointments and Meetings

[This is preliminary documentation and subject to change.]

Recurring appointments and meetings have one master and one or more recurring instances. To cancel an entire series of a recurring appointment or meeting, you need to cancel the master appointment or meeting. Each recurring instance has a GetRecurringMaster method that returns its master appointment or meeting.

To cancel a single instance of a recurring appointment or meeting, open the instance and cancel it. You cancel single instances the same way you cancel a single appointment or meeting; see Canceling an Appointment or Canceling a Meeting.

The basic process for canceling a recurring appointment or meeting is as follows:

  1. Open the calendar folder using an ADODB record set. Use the adOpenStatic and adLockOptimistic options on the Open method to enable deleting members of the record set. Specify a start and end time in the query so that instances are expanded in the calendar folder; see Calendar Folder Query.
  2. Locate any instance of the recurring appointment or meeting that you want to cancel and open it using an Appointment object.
  3. Open the master appointment using the Iappointment.GetRecurringMaster method. Verify that you are the organizer. Be sure to open the appointment or meeting in read/write mode using adModeReadWrite.
  4. Set the configuration and create a Calendar Message object using the IAppointment.Cancel method.
  5. Add any desired text to the Calendar Message object.
  6. Send the Calendar Message object using the IMessage.Send method.
  7. Delete the master appointment or meeting from the calendar folder (optional).

    Note   Once you delete the master appointment or meeting for an instance, do not try to delete the master again for another instance of the same master.

The following code example gets meetings in the specified date range from the calendar of a specific user with the subject "Documentation Review Meeting." It then gets the master meeting, verifies that the user is the organizer, and finally cancels the entire recurring meeting.

[Visual Basic]
Dim CalendarURL As String
Dim ItemURL     As String
Dim Rs          As New ADODB.Recordset
Dim Rec         As New ADODB.Record
Dim Rec2        As New ADODB.Record
Dim iAppt       As New CDO.Appointment
Dim iAppt2      As CDO.Appointment
Dim iAtnds      As CDO.IAttendees
Dim Config      As New CDO.Configuration
Dim iCalMsg     As CDO.CalendarMessage
Dim Address     As String
Dim Index       As Integer

CalendarURL = "file://./backofficestorage/" & DomainName & "/MBX/" & UserName & "/calendar/"

'Set the configuration fields
Config.Fields(cdoSendEmailAddress) = UserName & "@" & DomainName
Config.Fields.Update
Set iAppt.Configuration = Config

'Set the address of the user for comparing with the attendee value
Address = "MAILTO:" & UserName & "@" & DomainName

'Open the record set for the items in the calendar folder
Rec.Open CalendarURL
Set Rs.ActiveConnection = Rec.ActiveConnection
Rs.Source = "SELECT ""DAV:href"", " & _
                  " ""urn:schemas:httpmail:subject"", " & _
                  " ""urn:schemas:calendar:dtstart"", " & _
                  " ""urn:schemas:calendar:dtend"" " & _
            "FROM scope('shallow traversal of """ & CalendarURL & """') " & _
            "WHERE (""urn:schemas:calendar:dtstart"" >= CAST(""1999-10-01T08:00:00Z"" as 'dateTime')) " & _
            "AND (""urn:schemas:calendar:dtend"" <= CAST(""1999-11-01T08:00:00Z"" as 'dateTime'))" & _
            "AND (""urn:schemas:httpmail:subject"" = 'Documentation Review Meeting')"
Rs.Open , , adOpenStatic, adLockOptimistic

'Enumerate the record set
Rs.MoveFirst
Do Until Rs.EOF
  ItemURL = Rs.Fields(CdoDAV.cdoHref).Value
  iAppt.DataSource.Open ItemURL, , adModeReadWrite
  Set iAtnds = iAppt.Attendees
  For Index = 1 To iAtnds.Count
  'Check if this user is the organizer
  If iAtnds.Item(Index).IsOrganizer And iAtnds.Item(Index).Address = Address Then
    'This user is the organizer
    Set iAppt2 = iAppt.GetRecurringMaster(CalendarURL) 'Get the master
                                          'If already master, returns itself
    'Create a cancelation message
    iAppt2.Configuration = Config
    Set iCalMsg = iAppt2.Cancel
    iCalMsg.Message.TextBody = "This meeting is canceled."
    iCalMsg.Message.Send
    
    'Delete the master from the calendar folder (optional)
    ItemURL = iAppt2.Fields(CdoDAV.cdoHref)
    Rec2.Open ItemURL, , adModeReadWrite
    Rec2.DeleteRecord
    
    Exit Do 'Stop processing meeting instances
  End If
  Next Index
    
Rs.MoveNext
Loop