I need to get all the emails that have a specific category name, how would I do this?
Right now I have this:
var col = new List<SearchFilter>();
col.Add(new SearchFilter.ContainsSubstring(ItemSchema.Categories, "Processed"));
var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, col.ToArray());
FindItemsResults<Item> findResults = service.FindItems(
WellKnownFolderName.Inbox,
filter,
new ItemView(10)
);
But that gives me a Microsoft.Exchange.WebServices.Data.ServiceResponseException
that says {"The Contains filter can only be used for string properties."}
How would I do it?
AFAIK as of Exchange 2010, category is a multi value field so it does not work with search filters. However, you can search categories using AQS . The following code should do the trick.
ExchangeService service = GetService();
var iv = new ItemView(1000);
string aqs = "System.Category:Processed";
FindItemsResults<Item> searchResult = null;
do
{
searchResult = service.FindItems(WellKnownFolderName.Inbox, aqs, iv);
foreach (var item in searchResult.Items)
{
Console.WriteLine(item.Subject);
}
iv.Offset += searchResult.Items.Count;
} while (searchResult.MoreAvailable == true);
I use the following code, to find all messages, which do NOT have set the category "Processed" and which have been received after a given date.
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
new SearchFilter.Not(new SearchFilter.IsEqualTo(EmailMessageSchema.Categories, "Processed")),
new SearchFilter.IsGreaterThan(EmailMessageSchema.DateTimeReceived, minDate));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.