'How to use multiple conditions in single DASL filter query in C#? (Syntax) (for advancedSearch() method)
BACKGROUND:
Currently I am searching for a word in the subject of email in VSTO add-in. My syntax is:
string filter = "urn:schemas:mailheader:subject LIKE \'%" + wordInSubject + "%\'";
even the following syntax works:
string filter = String.Format("\"urn:schemas:mailheader:subject\" >= '{0}'", "ticket");
string filter = String.Format("@SQL=(\"urn:schemas:calendar:dtstart\" >= '{0:g}' " + "AND \"urn:schemas:calendar:dtend\" <= '{1:g}' " + "AND \"urn:schemas:mailheader:subject\" LIKE '%{2}%')", startTime, endTime, wordInSubject);
However, I also want to include DateTime comparison where the mail is between a time range.
REASEARCH LINKS:
I tried following ways, however they don't work:
string filter = ("urn:schemas:mailheader:subject LIKE \'%" + wordInSubject + "%\'") + ("[Start] >= '" + startTime.ToString("g") + "' + [End] <= '" + endTime.ToString("g") + "'");
string filter = ("urn:schemas:mailheader:subject LIKE \'%" + wordInSubject + "%\'") AND ("[Start] >= '" + startTime.ToString("g") + "' AND [End] <= '" + endTime.ToString("g") + "'");
Also, while searching I read that it should be prefixed with "@SQL=" - however, even that condition throws error:-
string filter = "@SQL=""urn:schemas:mailheader:subject LIKE \'%" + wordInSubject + "%\'"
PROBLEM STATEMENT:-
I am not looking for specifically DateTime case. But, I can work with just the syntax of using more than one condition in single filter string (any type of condition).
Solution 1:[1]
Try the following query that uses DASL property names:
@SQL=("http://schemas.microsoft.com/mapi/proptag/0x0E1D001F" LIKE '%test%') AND ("http://schemas.microsoft.com/mapi/proptag/0x0E060040" > '2017-09-25 00:00:00') AND ("http://schemas.microsoft.com/mapi/proptag/0x0E060040" < '2018-09-25 00:00:00')
It uses restriction on PR_NORMALIZED_SUBJECT_W
(DASL name http://schemas.microsoft.com/mapi/proptag/0x0E1D001F
) and PR_MESSAGE_DELIVERY_TIME
(DASL name http://schemas.microsoft.com/mapi/proptag/0x0E060040
).
DASL property names can be retrieved in OutlookSpy (I am its author) - click IMessage button, select the property, see the DASL text box.
Solution 2:[2]
Try the following query that uses DASL property names:
@SQL=("http://schemas.microsoft.com/mapi/proptag/0x0E1D001F" LIKE '%test%') AND ("http://schemas.microsoft.com/mapi/proptag/0x0E060040" > '2017-09-25 00:00:00') AND ("http://schemas.microsoft.com/mapi/proptag/0x0E060040" < '2018-09-25 00:00:00')
It uses restriction on PR_NORMALIZED_SUBJECT_W
(DASL name http://schemas.microsoft.com/mapi/proptag/0x0E1D001F
) and PR_MESSAGE_DELIVERY_TIME
(DASL name http://schemas.microsoft.com/mapi/proptag/0x0E060040
).
DASL property names can be retrieved in OutlookSpy (I am its author) - click IMessage button, select the property, see the DASL text box.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Dmitry Streblechenko |