Partager via


Modifying and deleting items in 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 modify or delete a calendar item that belongs to a recurring series of calendar items. This topic contains information about how to modify or delete a single calendar item in a recurring series. For information about how to update all items in a recurring series, see Updating a recurring series by using the EWS Managed API 2.0. For information about how to delete all items in a recurring series, see Deleting a recurring series by using the EWS Managed API 2.0.

To modify a calendar item in a recurring series

  1. Bind to an existing calendar item in a recurring series. The following code shows how to bind to the third item in a recurring series and provide it with connection configuration information by using an ExchangeService object named service. The string sRecurringMasterId represents the unique identifier of the recurring master item for the series. For more information about how to bind to a calendar item in a recurring series, see Accessing calendar items in a recurring series by using the EWS Managed API 2.0.

    Appointment occurrence = Appointment.BindToOccurrence(service, new ItemId(sRecurringMasterId), 3);
    
  2. Update properties on the calendar item. The following code shows how to update the subject, the start time, and the end time on an appointment.

    occurrence.Subject = "Urgent Status Update – Rescheduled for March 5, 2009";
    occurrence.Start = new DateTime(2009, 3, 5, 9, 0, 0);
    occurrence.End = occurrence.Start.AddHours(1);
    
  3. Save the updated calendar item. When the modified calendar item is saved, it becomes an exception item in the recurring series. For information about how to identify and access the exception items 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 save an updated calendar item. For a list of the methods that you can use to save or to save and send updated appointments or meeting requests, see Updating appointments and meetings by using the EWS Managed API 2.0.

    occurrence.Update(ConflictResolutionMode.AlwaysOverwrite);
    

To delete a calendar item in a recurring series

  1. Bind to an existing calendar item in a recurring series. The following code shows how to bind to the third item in a recurring series and provide it with connection configuration information by using an ExchangeService object named service. The string sRecurringMasterId represents the unique identifier of the recurring master item for the series. For more information about how to bind to a calendar item in a recurring series, see Accessing calendar items in a recurring series by using the EWS Managed API 2.0.

    Appointment occurrence = Appointment.BindToOccurrence(service, new ItemId(sRecurringMasterId), 3);
    
  2. Delete the calendar item. The following code shows how to delete an appointment in a recurring series by using the Delete method. For more information about the methods that you can use to delete an appointment or cancel a meeting, see Deleting appointments and canceling meetings by using the EWS Managed API 2.0. For information about how to identify the deleted items in a recurring series, see Accessing calendar items in a recurring series by using the EWS Managed API 2.0.

    occurrence.Delete(DeleteMode.MoveToDeletedItems);
    

Example

Modifying a calendar item in a recurring series

The following code example shows how to update the subject, the location, the start time, and the end time for an appointment that belongs to a recurring series of appointments. This example assumes that service is a valid ExchangeService binding. The string sRecurringMasterId represents the unique identifier of the recurring master item for the series. For more information about how to bind to a calendar item in a recurring series, see Accessing calendar items in a recurring series by using the EWS Managed API 2.0. For a list of the methods that you can use to save or to save and send updated appointments or meeting requests, see Updating appointments and meetings by using the EWS Managed API 2.0.

// Bind to the third occurrence in a recurring series of appointments.
Appointment occurrence = Appointment.BindToOccurrence(service, new ItemId(sRecurringMasterId), 3);

// Update subject, location, start time, and end time of the appointment.
occurrence.Subject = "Status Meeting – New Time & Location";
occurrence.Location = "Conf Room 34";
occurrence.Start = new DateTime(2009, 3, 5, 10, 0, 0);
occurrence.End = occurrence.Start.AddHours(1);

// Save the modified appointment.
occurrence.Update(ConflictResolutionMode.AlwaysOverwrite);

Deleting a calendar item in a recurring series

The following code example shows how to delete an appointment that belongs to a recurring series of appointments. This example assumes that service is a valid ExchangeService binding. The string sRecurringMasterId represents the unique identifier of the recurring master item for the series. For more information about how to bind to a calendar item in a recurring series, see Accessing calendar items in a recurring series by using the EWS Managed API 2.0. For more information about the methods that you can use to delete an appointment or cancel a meeting, see Deleting appointments and canceling meetings by using the EWS Managed API 2.0.

// Bind to the third occurrence in a recurring series of appointments.
Appointment occurrence = Appointment.BindToOccurrence(service, new ItemId(sRecurringMasterId), 3);

// Delete the appointment.
occurrence.Delete(DeleteMode.MoveToDeletedItems);

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.