Search code examples
outlookoutlook-addin

Outlook Custom field filtering using MAPI


I try to filter custom properties get contacts in a Outlook. I saved user property call "SyncValue". It have string values. And I try to check these values and get the contactitem have that property value.

Outlook.ContactItem contactItem = null;
string syncVal = (char)34 + "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/SyncValue" + (char)34;
Outlook.MAPIFolder contacts = Globals.objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items contactItems = contacts.Items;
string filter = "WHERE (" + syncVal + " = 'True')";
contactItem = contactItems.Find(filter) as Outlook.ContactItem;

Solution

  • Your filter string must be prefixed with @SQL=. You should not use "WHERE":

    string filter = "@SQL=" + syncVal + " = 'True')";