EWS - how can I find all incomplete tasks?
I am using Exchange Web Services to try and get a list of all Outlook tasks that have not completed.
I have an instance of ExchangeService and am trying to find all pending tasks like this:
SearchFilter searchFilter = new SearchFilter.IsNotEqualTo(TaskSchema.Status, TaskStatus.NotStarted);
FindItemsResults<Item> tasks = service.FindItems(WellKnownFolderName.Tasks, searchFilter, view);
However, on the last line, I get "ServiceResponseException: The specified value is not valid for the property." This strikes me as odd because the EWS documentation explicitly states that Task.Status should be one of the values of the TaskStatus enumeration. Making a SearchFilter that compares to a string value doesn't throw an exception, but I haven't tried any of the other enumeration options to see if they give the same behavior.
source to share
I can do this with ExtendedPropertyDefinition since Exchange 2007.
I am using PidLidTaskComplete Canonical Property .
A complete list of named properties available here .
//Create the extended property definition.
ExtendedPropertyDefinition taskCompleteProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Task, 0x0000811C, MapiPropertyType.Boolean);
//Create the search filter.
SearchFilter.IsEqualTo filter = new SearchFilter.IsEqualTo(taskCompleteProp, false);
//Get the tasks.
FindItemsResults<Item> tasks = service.FindItems(WellKnownFolderName.Tasks, filter, new ItemView(50));
source to share
I believe you can also achieve this without using magic numbers:
var view = new ItemView(20);
var query = new SearchFilter.IsNotEqualTo(TaskSchema.IsComplete, true);
var results = exchangeService.FindItems(WellKnownFolderName.Tasks, query, view);
This works with specific exchange version :)
source to share