BACKGROUND:
Currently I am searching for the MailItems which belong to the Result set of advancedSearch() Query.
Outlook.Search advancedSearch = Application.AdvancedSearch(scope, filter, true, advancedSearchTag);
Outlook.Results advancedSearchResults = advancedSearch.Results;
foreach (MailItem item in advancedSearchResults)
{
MessageBox.Show(item.Subject.ToString());
}
PROBLEM STATEMENT:
I want to search and loop on MailItems which doesnot satisfy the "filter" of this advancedSearch() method. Is there any way to do so?
If NO. Is there any work around for it? (either using Find() or Restrict()) My specific case is to search, if UserProperty of each MailItem is "ABC" or not. (not it's value, but the name of the UserProperty)
here, I am using:
string filter = "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046} LIKE \'%" + propertyName + "%\'";
Thanks.
Firstly, prepend your search with "NOT". Secondly, add the "is null" or "is not null" clauses - your search query assumes the property exists on each item. If it doesn't, the result is undefined.