I have a program that loops all emails in Office 365 using the EWS services and if the match some criteria they get tagged with a category. I then what to create a seachfolder that looks mails that has the category.
This is my code
SearchFolder searchFolder = new SearchFolder(service);
SearchFilter filter = new SearchFilter.ContainsSubstring(ItemSchema.Categories, categoryName);
searchFolder.DisplayName = "Mulige CPR-data";
searchFolder.SearchParameters.RootFolderIds.Add(WellKnownFolderName.Inbox);
searchFolder.SearchParameters.Traversal = SearchFolderTraversal.Deep;
searchFolder.SearchParameters.SearchFilter = filter;
try
{
searchFolder.Save(WellKnownFolderName.SearchFolders);
Console.WriteLine(searchFolder.DisplayName + " added.");
}
catch (Exception e)
{
//error handling
}
The Seachfolder is created but when i access it in Outlook 365 I get a message saying something like "Nothing found" (I have the danish version, so not sure about the english message).
After som trial and error I found that i this instead it works fine
SearchFilter filter = new SearchFilter.ContainsSubstring(ItemSchema.Subject, "subjectTest");
So my question is why are my seachfolder not working when using categories but working fine when checking for something i the subject.
Bonus info - If I create a seachfolder in outlook using the same seach criteria(category) it works fine.