Search code examples
c#exchangewebservicesews-managed-api

Filter on specific classes in the inbox using EWS Managed API


I need to get all emails of the class MeetingCancellation from an inbox of a shared mailbox. Unfortunately, I have no idea how to filter on the classes with EWS Managed API.

I need to filter, to get this piece of code working and not throw an exception every time, it tries to process a normal email:

List<MeetingCancellation> findResultsList = findResults.Select<dynamic, MeetingCancellation>(x => { return ConvertItemHelper(x); }).ToList();

I can't use the GetType() method, because findResults is an Object of the FindItemsResults<Item>class (=> I can't find out, wether it is a MeetingCancellation or not).

I'm coding in c#.


Solution

  • You would be better to just use a SearchFilter to limit whats returned from the server to just the Meeting cancelcation eg something like

     SearchFilter sf1 = new SearchFilter.IsEqualTo(EmailMessageSchema.ItemClass, "IPM.Schedule.Meeting.Canceled");
     FindItemsResults<Item> Results = service.FindItems(WellKnownFolderName.Inbox,sf1, ItemViewObj);
    

    also

    findResults.Where(x => x.ItemClass == "IPM.Schedule.Meeting.Canceled");
    

    Should work