I\'m trying to get number of unread emails from Exchange for specific user.
I\'m able to get number of emails from Inbox like so:
SearchFilter sf = n
Not sure it's what you were looking for, but... Getting unread emails counts (inbox / draft etc.):
int x = Folder.Bind(yourService, WellKnownFolderName.Inbox).UnreadCount;
int y = Folder.Bind(yourService, WellKnownFolderName.Drafts).UnreadCount;
return x + y;
In this case, the service is called two times, but the calls are issued sequentially - not good enough.
Though, you can issue both requests at the same time and increase the response time of your app.
See this or any tutorial that explains how to instantiate two TPL tasks, send them to the task scheduler, wait for both (WaitAll()) to complete and, in the end, retrieve their results :)
And, if you want to get the email counts after applying some custom filters (not the trivial 'unread' filter), then make sure that your ItemView object is ItemView(1), not ItemView(int.MaxValue). Then, get the total count:
int n = findItemsResults.TotalCount;
See the docs for TotalCount property.
This way, the service response is quite small - it contains only one item, but it (the response) also carries the total count... That's what you want, right?