Programmatically filtering contacts in Outlook 2010 Add-In

Posted by Leon Havin on Stack Overflow See other posts from Stack Overflow or by Leon Havin
Published on 2012-09-04T03:33:52Z Indexed on 2012/09/04 3:38 UTC
Read the original article Hit count: 223

Filed under:
|
|
|
|

I am trying to programmatically filter Outlook contacts in the Contacts folder in Outlook 2010. I followed DASL filter rules, but it seems working for Find function and throws exception when I assign this filter to view.Filter = FilterString. Any ideas what I am doing wrong? The correct result would display filtered contacts in the existing contacts view.

Outlook.Application myApp = ThisAddIn.myApp; 
Outlook.NameSpace myNamespace = ThisAddIn.nSpace; 
Outlook.MAPIFolder myContactsFolder = ThisAddIn.contactsFolder;
if (myContactsFolder == null)
{
    Log.Verbose("Contacts folder not found");
    return null;
}

Outlook.Items contactItems = ThisAddIn.contactItems; 

//use filter to take only contact and not DistListItem  
Outlook.Items outlookContacts = contactItems.Restrict("[MessageClass] = 'IPM.Contact'");
Outlook.ContactItem contact = null;

int iOutlookContacts = contactItems.Count;
if (iOutlookContacts > 0)
{
    string FilterString = "[FullName]='" + param + "'"; 

    // Find works with this filter
    contact = (Outlook.ContactItem)outlookContacts.Find(FilterString); 
    if (contact != null)
    {
        // need to display in contacts search window
        Outlook.View currentView = myApp.ActiveExplorer().CurrentView;
        currentView.Filter = FilterString; // cannot parse exception occurs here

        currentView.Save();
        currentView.Apply();
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about outlook