我正在尝试以编程方式筛选 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/