Search appointments by required or optional attendees

Hi there

I need to search appointments by required or optional attendees using EWS. I've tried with a search filter collection and a query string but none of these options worked.

Search Filter Collection

var attendeeFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or)
            {
                new SearchFilter.ContainsSubstring(AppointmentSchema.RequiredAttendees, mailAddress),
                new SearchFilter.ContainsSubstring(AppointmentSchema.OptionalAttendees, mailAddress),
            };

FindItemsResults<Item> results = ews.FindItems(WellKnownFolderName.Calendar, attendeeFilter, view);

Query String

string queryString = string.Format("(RequiredAttendees:{0} OR OptionalAttendees:{0})", mailAddress);

FindItemsResults<Item> results = ews.FindItems(WellKnownFolderName.Calendar, queryString, view);

Does anyone know the magic trick to achieve this?

June 11th, 2015 4:57pm

ContainsSubstring() approach works on Exchange 2010 but doesn't on Exchange 2013.

+1 to the author's question.

Anton

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2015 8:56am

The indexed property should be Participants https://technet.microsoft.com/en-us/library/jj983804(v=exchg.150).aspx so something like

string queryString = "Participants:user@domain.com";
FindItemsResults<Item> results = ews.FindItems(WellKnownFolderName.Calendar, queryString, view);

Should work

Cheers
Glen

July 12th, 2015 9:19pm

Hi Glen

Thanks for your hint. Searching for participants does work now. But using a query string leads to another problem. I have to search for appointments between a specific date range. That wasn't a problem with a SearchCollection. But AQS doesn't seem to have an indexed property for the start date of an appointment (just the sent and received date). Do you have any idea how to search for appointments by participants and a date range?

I've already tried to use a CalendarView in combination with a CalendarFolder. That works for the date range but I can't specify a query string.

Regards,
Manuel

Free Windows Admin Tool Kit Click here and download it now
July 16th, 2015 5:03am

That type of query isn't supported AFAIK my suggestion is if you want to query for a time period then just use the CalendarView and filter the appointments at the client side. The reason to use a calendarview is when you want to also get recurrence expansion which won't happen if you use AQS or SearchFilters. Calendars don't generally contain that many items so really complex queries offer very little value anyway and may end up being performance negative.

Cheers
Glen

July 16th, 2015 11:03pm

That type of query isn't supported AFAIK my suggestion is if you want to query for a time period then just use the CalendarView and filter the appointments at the client side. The reason to use a calendarview is when you want to also get recurrence expansion which won't happen if you use AQS or SearchFilters. Calendars don't generally contain that many items so really complex queries offer very little value anyway and may end up being performance negative.

Cheers
Glen

  • Marked as answer by Manuel1 22 hours 18 minutes ago
Free Windows Admin Tool Kit Click here and download it now
July 17th, 2015 3:01am

Thank you Glen. It works now!

ExchangeService ews = CreateExchangeService();

var calendarFolder = CalendarFolder.Bind(ews, WellKnownFolderName.Calendar, new PropertySet());

var calendarView = new CalendarView(DateTime.Now.AddDays(-14), DateTime.Now.AddDays(14))
{
     Traversal = ItemTraversal.Shallow
};

FindItemsResults<Appointment> appointments = calendarFolder.FindAppointments(calendarView);

ews.LoadPropertiesForItems(appointments, new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.DateTimeReceived, AppointmentSchema.RequiredAttendees,
AppointmentSchema.OptionalAttendees, AppointmentSchema.Organizer));

IEnumerable<Appointment> commonAppointments = appointments.Where(x => x.RequiredAttendees.Any(a => string.Equals(a.Address, mailAddress, StringComparison.OrdinalIgnoreCase))
|| x.OptionalAttendees.Any(a => string.Equals(a.Address, mailAddress, StringComparison.OrdinalIgnoreCase))
|| string.Equals(x.Organizer.Address, mailAddress, StringComparison.OrdinalIgnoreCase));

Important: I've had to load the property definition after the search. Defining the property set inside the calendar view won't work with RequiredAttendees and OptionalAttendees.


  • Edited by Manuel1 22 hours 19 minutes ago
  • Marked as answer by Manuel1 22 hours 18 minutes ago
July 23rd, 2015 5:09am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics