Search code examples
c#asp.netexchangewebservicesews-managed-api

EWS Search Appointments by Subject


I'm using EWS Managed API 2.0. I would like to be able to search a calendar in exchange on the subject of the appointment in the future.

The caveats are:

  1. only return future appointments matching the subject="test"
  2. only return future appointments in the next 90 days

I can get CalendarView to return appointments in the next 90 days, but cannot figure out how to filter using a SearchFilter. For best performance, I'd rather not return all appointments and then filter.

I can filter the appointments by Subject using ItemView and a SearchFilter. However this doesn't filter out appointments that have already occurred. It returns everything matching the filter.

Ideally, it would be nice if I could use a CalendarView in the SearchFilter but I receive the error "Restrictions and sort order may not be specified for a CalendarView."

FindItemsResults<Item> findResults = svc().FindItems(fId, filter, cView);

Any help would be great... thank you!


Solution

  • I figured it out....

    Using compound search filters, like so

            SearchFilter.SearchFilterCollection coll = new SearchFilter.SearchFilterCollection(LogicalOperator.And);            
            SearchFilter subjectFilter = new SearchFilter.ContainsSubstring(AppointmentSchema.Subject, "test");
            SearchFilter dateFilter = new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, DateTime.Today);
            coll.Add(subjectFilter);
            coll.Add(dateFilter);
    
            FindItemsResults<Item> findResults = svc().FindItems(fId, coll, view);