Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EWS - how do I find all incomplete tasks?

I am using Exchange Web Services to try to get a list of all Outlook tasks which are not complete.

I have an instance of ExchangeService, and attempt to find all incomplete 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 a "ServiceResponseException: The specified value is invalid for property." This seems weird to me because the EWS documentation explicitly states that the Task.Status is supposed to be one of the TaskStatus enumeration values. Creating a SearchFilter which compares against a string value does not cause an exception, but I haven't tried any of the other enumeration options to see whether they give the same behavior.

like image 941
Geir Smestad Avatar asked Dec 05 '25 08:12

Geir Smestad


2 Answers

I am able to do this using ExtendedPropertyDefinition with Exchange 2007.

I am using PidLidTaskComplete Canonical Property.

Full 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));
like image 169
Paul Patterson Avatar answered Dec 07 '25 23:12

Paul Patterson


I believe you may also achieve that without using any magic numbers:

var view = new ItemView(20);
var query = new SearchFilter.IsNotEqualTo(TaskSchema.IsComplete, true);
var results = exchangeService.FindItems(WellKnownFolderName.Tasks, query, view); 

This does work on a certain version of exchange :)

like image 35
turdus-merula Avatar answered Dec 07 '25 23:12

turdus-merula



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!