EWS - how do I find all incomplete tasks?

那年仲夏 提交于 2020-01-04 03:52:08

问题


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.


回答1:


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));



回答2:


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 :)



来源:https://stackoverflow.com/questions/9823489/ews-how-do-i-find-all-incomplete-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!