我正在开发一个C#表单应用程序,我必须在一个步骤中显示(在列表框中)默认Outlook帐户中指定了公司的所有联系人。
我提出了以下功能:
outlookContactsList = new List<OutlookContactData>();
Outlook.Application outlookApp = new Outlook.Application();
Outlook.Items OutlookItems;
Outlook.Items FilteredOutlookItems;
Outlook.MAPIFolder Folder_Contacts;
Folder_Contacts = (Outlook.MAPIFolder)outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
OutlookItems = Folder_Contacts.Items;
String CompanyMatch = "[CompanyName] <> ''";
FilteredOutlookItems = OutlookItems.Restrict(CompanyMatch);
var contactlist = new System.Collections.Generic.List<string>();
foreach (Object _obj in FilteredOutlookItems)
{
if (_obj is Outlook.ContactItem)
{
Outlook.ContactItem contact = (Outlook.ContactItem)_obj;
if (contact != null)
{
if (contact.CompanyName != null && contact.CompanyName != string.Empty && contact.CompanyName != " ")
{
OutlookContactData ocd = new OutlookContactData();
if (contact.FullName != null && contact.FullName != string.Empty)
{
ocd.DisplayMember = contact.CompanyName + " - " + contact.FullName;
}
else
{
ocd.DisplayMember = contact.CompanyName;
}
ocd.ContactID = contact.EntryID;
outlookContactsList.Add(ocd);
}
}
}
}
阅读几百个条目的联系人列表需要几秒钟......有什么方法可以改善这一点吗?
答案 0 :(得分:0)
使用MAPIFolder.GetTable
- 请参阅https://msdn.microsoft.com/en-us/library/office/ff860692.aspx