Deleting a recurring series by using the EWS Managed API 2.0

Last modified: October 13, 2012

Applies to: EWS Managed API | Exchange Server 2007 Service Pack 1 (SP1) | Exchange Server 2010

Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.

You can use the Microsoft Exchange Web Services (EWS) Managed API to delete a recurring series of calendar items. This topic contains information about how to delete a recurring series of appointments and cancel a recurring series of meetings. For information about how to delete a single appointment in a recurring series of appointments or cancel a single meeting in a recurring series of meetings, see Modifying and deleting items in a recurring series by using the EWS Managed API 2.0.

To delete a recurring series of appointments

  1. Bind to the recurring master item for the series you want to delete by using its unique identifier. For information about how to get the unique identifier of the recurring master item in a recurring series, see Accessing calendar items in a recurring series by using the EWS Managed API 2.0. The following code shows how to bind to an existing recurring master item and provide it with connection configuration information by using an ExchangeService object named service. The ItemId has been shortened to preserve readability.

    Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));
    
  2. Delete the appointment. The following code shows how to delete a recurring series of appointments and move the recurring appointment to the Deleted Items folder. Before performing the deletion, it verifies that the appointment is a recurring master item.

    if (appointment.AppointmentType == AppointmentType.RecurringMaster)
    {
       appointment.Delete(DeleteMode.MoveToDeletedItems);
    }
    

To cancel a recurring series of meetings

  1. Bind to the recurring master item for the series you want to cancel by using its unique identifier. For information about how to get the unique identifier of the recurring master item in a recurring series, see Accessing calendar items in a recurring series by using the EWS Managed API 2.0. The following code shows how to bind to an existing recurring master item and provide it with connection configuration information by using an ExchangeService object named service. The ItemId has been shortened to preserve readability.

    Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));
    
  2. Cancel the recurring series. You can cancel a recurring series of meetings by using one of the following:

    • The CancelMeeting method, sending a generic cancellation message to all attendees, as shown in the following code. Before performing the deletion, the code verifies that the appointment is a recurring master item.

      if (appointment.AppointmentType == AppointmentType.RecurringMaster)
      {
         appointment.CancelMeeting();
      }
      
    • The CancelMeeting method, sending a customized cancellation message to all attendees, as shown in the following code. Before performing the deletion, the code verifies that the appointment is a recurring master item.

      if (appointment.AppointmentType == AppointmentType.RecurringMaster)
      {
         appointment.CancelMeeting("The project has ended and these weekly status meetings are no longer necessary.");
      }
      
    • The Delete method, as shown in the following code. Before performing the deletion, the code verifies that the appointment is a recurring master item. The meeting request is moved to the Deleted Items folder and a cancellation message is sent to all attendees.

      if (appointment.AppointmentType == AppointmentType.RecurringMaster)
      {
         appointment.Delete(DeleteMode.MoveToDeletedItems, SendCancellationsMode.SendOnlyToAll);
      }
      
    • The CreateCancelMeetingMessage method, creating a customized cancellation message and requesting a read receipt from recipients, as shown in the following code. Before performing the deletion, the code verifies that the appointment is a recurring master item. The cancellation message is sent to all attendees and a copy of the cancellation message is saved in the sender's Sent Items folder.

      if (appointment.AppointmentType == AppointmentType.RecurringMaster)
      {
         CancelMeetingMessage cancelMessage = appointment.CreateCancelMeetingMessage();
         cancelMessage.Body = new MessageBody("The project has ended and these weekly status meetings are no longer necessary.");
         cancelMessage.IsReadReceiptRequested = true;
         cancelMessage.SendAndSaveCopy();
      }
      

Example

Deleting a recurring series of rappointments

The following code example shows how to delete a recurring series of appointments and move the recurring appointment to the Deleted Items folder. This example assumes that service is a valid ExchangeService binding. The ItemId has been shortened to preserve readability.

// Bind to the recurring master item for the series by using its unique identifier.
Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));

// If the appointment is a recurring master item, delete the series and move the recurring appointment to the Deleted Items folder. 
if (appointment.AppointmentType == AppointmentType.RecurringMaster)
{
   appointment.Delete(DeleteMode.MoveToDeletedItems);
}

Canceling a recurring series of rmeetings

The following code example shows how to cancel a recurring series of meetings and send a customized cancellation message to all attendees. This example assumes that service is a valid ExchangeService binding. The ItemId has been shortened to preserve readability.

// Bind to the recurring master item for the series by using its unique identifier.
Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));

// If the appointment is a recurring master item, cancel the series and send a customized cancellation message to all attendees. 
if (appointment.AppointmentType == AppointmentType.RecurringMaster)
{
   appointment.CancelMeeting("The project has ended and these weekly status meetings are no longer necessary.");
}

Compiling the code

For information about compiling this code, see Getting started with the EWS Managed API 2.0.

Robust programming

  • Write appropriate error handling code for common search errors.

  • Review the client request XML that is sent to the Exchange server.

  • Review the server response XML that is sent from the Exchange server.

  • Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API 2.0. Do not hard code URLs because if mailboxes move, they might be serviced by a different Client Access server. If the client cannot connect to the service, retry setting the binding by using the AutodiscoverUrl(String) method.

  • Set the target Exchange Web Services schema version by setting the requestedServerVersion parameter of the ExchangeService constructor. For more information, see Versioning EWS requests by using the EWS Managed API 2.0.

Security

  • Use HTTP with SSL for all communication between client and server.

  • Always validate the server certificate that is used for establishing the SSL connections. For more information, see Validating X509 certificates by using the EWS Managed API 2.0.

  • Do not include user names and passwords in trace files.

  • Verify that Autodiscover lookups that use HTTP GET to find an endpoint always prompt for user confirmation; otherwise, they should be blocked.