Finding an appointment by ID on EWS

Alasdair North - 

I've been writing an app that creates and updates appointments in Exchange using Exchange Web Services (EWS). For some reason I couldn't find out how to fetch an appointment by ID/UniqueId.

I started by trying to search for the appointment by ID (id being a string taken from appointments Id.UniqueId).

var appointmentSearch = service.FindItems(
    WellKnownFolderName.Calendar,
    new SearchFilter.IsEqualTo(ItemSchema.Id, id),
    new ItemView(1));

But this gives you a Microsoft.Exchange.WebServices.Data.ServiceResponseException with the message "The specified value is invalid for property".

Then I tried wrapping it in an ItemId object.

var appointmentSearch = service.FindItems(
    WellKnownFolderName.Calendar,
    new SearchFilter.IsEqualTo(ItemSchema.Id, new ItemId(id)),
    new ItemView(1));

But that gives you a System.ArgumentException with "Validation failed. Parameter name: searchFilter", and an inner exception stating "Values of type 'ItemId' can't be used as comparison values in search filters".

The correct approach isn't to search at all, it's to use Appointment.Bind.

var appointment = Appointment.Bind(service, new ItemId(id));
← other fixes or blog
Father of three, CTO of viaLibri, and an active member of St. Barnabas Church.

Latest Posts

comments powered byDisqus