I am developing an Outlook add-in that communicates with EWS (in this case Office 365) and am trying to delete appointments by category. Each appointment has two categories. I am using SearchFilter to get a FindItemResults collection which I then use to delete appointments.
When the SearchFilter is set to IsEqualTo everything works but items are only found if the category named in the search filer comes first of the two. Setting the SearchFilter to ContainsSubstring ought to fix this but EWS returns an exception on the last line of the code block below.
searchFilterCollection.Add(new SearchFilter.IsEqualTo(ItemSchema.Categories, category.Trim())); searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchFilterCollection.ToArray()); //Find items to delete ItemView view = new ItemView(500); view.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start); findResults = exchangeService.FindItems(WellKnownFolderName.Calendar, searchFilter, view);
The error details are:
Error at InternalThrowIfNecessary : Microsoft.Exchange.WebServices.Data.ServiceResponseException An internal server error occurred. The operation failed. <o:p></o:p>
Message: An internal server error occurred. The operation failed.
Site: InternalThrowIfNecessary
Stack Trace: at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
at Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary()
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable`1 parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view, Grouping groupBy, ServiceErrorHandling
errorHandlingMode)<o:p></o:p>
at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(FolderId parentFolderId, SearchFilter searchFilter, ItemView view)<o:p></o:p>
at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(WellKnownFolderName parentFolderName, SearchFilter searchFilter, ItemView view)<o:p></o:p>
at GreenhillSoftware.ACalWinFormLib.Logic.ExchangeServiceManager.DeleteAppointmentsInExchange(String category, DateTime start, DateTime end, Form frm, String staffCode) in c:\VS Projects\Outlook Add-ins\ACal4\ACalWinFormLib\Logic\clsExchangeServiceManager.cs:line 864<o:p></o:p>