2

我正在尝试以编程方式过滤 Outlook 2010 中“联系人”文件夹中的 Outlook 联系人。我遵循 DASL 过滤器规则,但是Find当我将此过滤器分配给view.Filter = FilterString. 任何想法我做错了什么?正确的结果将在现有联系人视图中显示过滤的联系人。

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();
    }
}
4

1 回答 1

3

您需要将 DASL 搜索过滤器更改为:

string FilterString = "\"urn:schemas:contacts:cn\"='" + param + "'"; 

[FullName]不是有效的搜索过滤器列。全名字映射到 DASL 搜索列urn:schemas:contacts:cn

于 2012-09-04T14:01:15.910 回答