EWS Managed API find items with ItemID

nilobarp picture nilobarp · Dec 13, 2013 · Viewed 16.1k times · Source

I am trying to find items from deleted items folder given the items unique id

ItemId id = new ItemId("zTK6edxaI9sb6AAAQKqWHAAA");
SearchFilter.IsEqualTo filter = new SearchFilter.IsEqualTo(ItemSchema.Id, id);
ItemView view = new ItemView(10);
view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Subject);
FindItemsResults<Item> results = _ExchangeService.FindItems(WellKnownFolderName.DeletedItems, filter, view);
Console.WriteLine(results.TotalCount);

This code returns an exception saying:

Validation failed.
Parameter name: searchFilter

The same code works if I search for a message with Subject.

Answer

Abhi picture Abhi · May 18, 2015

You don't need to use FindItems if you already know the ItemId

EmailMessage email = EmailMessage.Bind(service, new ItemId(StringItemId));