Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Adding and removing meeting attendees by using the EWS Managed API 2.0

EWS Managed API

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.

In Exchange Web Services, a calendar item can represent a meeting between multiple parties. Meeting attendees are stored on the calendar item in one of three collections. These collections are listed in the following table.

Collection name

Description

RequiredAttendees

Contains attendees who must attend the meeting.

OptionalAttendees

Contains attendees who are not required to attend the meeting.

Resources

Contains meeting resources such as meeting rooms or equipment.

You can use the Microsoft Exchange Web Services (EWS) Managed API to add attendees to and remove attendees from meetings.

To add attendees to a meeting request

  1. Bind to an existing meeting request by using its unique identifier or create a new meeting request by instantiating the Appointment object.

    • The following code shows how to bind to an existing meeting request 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="));
      
    • The following code shows how to create a meeting request and provide it with connection configuration information by using an ExchangeService object named service.

      Appointment appointment = new Appointment(service);
      
  2. Set properties on the meeting request. The following code shows how to add two required attendees, an optional attendee, and a resource attendee to a meeting request.

    appointment.RequiredAttendees.Add("user1@contoso.com");
    appointment.RequiredAttendees.Add("user2@contoso.com");
    appointment.OptionalAttendees.Add("user3@contoso.com");
    appointment.Resources.Add("resource1@contoso.com");
    
    
  3. Save the meeting and send a meeting request message to attendees. The following code shows how to save a new meeting, send a meeting request message to all attendees, and save a copy of the meeting request message to the Sent Items folder. For information about the methods that you can use to save and send new meeting requests, see Creating appointments and meetings by using the EWS Managed API 2.0.

    appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
    
    NoteNote

    If you are updating an existing meeting request, use the Update method instead of the Save method to save the meeting request and send a meeting request message to the attendees. For information about the methods that you can use to save and send updated meeting requests, see Updating appointments and meetings by using the EWS Managed API 2.0.

To remove attendees from a meeting request

  1. Bind to an existing meeting request by using its unique identifier. The following code shows how to bind to an existing meeting request 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. Update the attendees to remove all required, optional, or resource attendees, or to remove a specific attendee.

    The following code shows how to remove all attendees from the OptionalAttendees collection on the meeting request.

    appointment.OptionalAttendees.Clear();
    

    To remove a specific attendee, loop through the attendees collection that contains the attendee that you want to remove, identify the attendee in the collection by using the attendee’s e-mail address, and remove the attendee from the collection. The following code shows how to remove user1@contoso.com from the RequiredAttendees collection on the meeting request.

    
    for (int i = 0; i < appointment.RequiredAttendees.Count; i++)
    {
        if ((appointment.RequiredAttendees[i].Address).ToUpper() == ("user1@contoso.com").ToUpper())
        {
            appointment.RequiredAttendees.RemoveAt(i);
            break;
        }
    }
    
  3. Save the meeting and send a meeting cancellation message to the attendee or attendees that you removed. The following code shows how to save a meeting and send a meeting cancellation message to user1@contoso.com.

    appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendOnlyToChanged);
    

Adding attendees to a meeting request

The following code example shows how to add user1@contoso.com as a new required attendee and user2@contoso.com as a new optional attendee to an existing meeting request. The updated meeting request is sent only to the attendees who were added. This example assumes that service is a valid ExchangeService binding. The ItemId has been shortened to preserve readability.

// Bind to an existing meeting request by using its unique identifier.
Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));

// Add a new required attendee to the meeting request.
appointment.RequiredAttendees.Add("user1@contoso.com");

// Add a new optional attendee to the meeting request.
appointment.OptionalAttendees.Add("user2@contoso.com");

// Save the updated meeting request and send only to the attendees who were added.
appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendOnlyToChanged);

Removing attendees from a meeting request

The following code example shows how to remove required attendee user1@contoso.com from an existing meeting request. The meeting cancellation message is sent only to the attendee who was removed. This example assumes that service is a valid ExchangeService binding. The ItemId has been shortened to preserve readability.

// Bind to an existing meeting request by using its unique identifier.
Appointment appointment = Appointment.Bind(service, new ItemId("AAMkA="));

// Remove a required attendee from the meeting request.
for (int i = 0; i < appointment.RequiredAttendees.Count; i++)
{
    if ((appointment.RequiredAttendees[i].Address).ToUpper() == ("user1@contoso.com").ToUpper())
    {
        appointment.RequiredAttendees.RemoveAt(i);
        break;
    }
}
// Save the updated meeting request and send the meeting cancellation message to the attendee who was removed.
appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendOnlyToChanged);

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

  • 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.

  • 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.

Show:
© 2015 Microsoft