c# - 以编程方式过滤 Outlook 2010 加载项中的联系人

标签 c# outlook vsto filtering contacts

我正在尝试以编程方式筛选 Outlook 2010 中“联系人”文件夹中的 Outlook 联系人。我遵循 DASL 筛选规则,但它似乎适用于 Find当我将此过滤器分配给 view.Filter = FilterString 时,函数并抛出异常。有什么想法我做错了吗?正确的结果将在现有联系人 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();
    }
}

最佳答案

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

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

[FullName] 不是有效的搜索过滤器列。 全名字段 maps to the DASL search column urn:schemas:contacts:cn

关于c# - 以编程方式过滤 Outlook 2010 加载项中的联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12256457/

相关文章:

visual-studio-2010 - 更改 csproj 文件中的 PublishUrl 属性

c# - 包含其他环境变量的 PATH 环境变量

c# - 使用 OpenXML 在 Word 2010 和 2003 中嵌入 Excel 图形

c# - 将经过身份验证的用户发送到 WCF 应用程序

c# - 向WPF Surface应用程序添加声音效果

html - Outlook.com/Outlook 2013 上的圆形按钮使用 TD

outlook - 使用HTML正文发送Outlook 2007 session 请求

c# - 测试 Outlook VSTO 加载项

c# - 如何获取 Outlook 中刚刚删除的项目?

c# - 无法选择部分超链接范围