我正在开发一个应用程序,允许用户用户查看他们有权访问的收件箱的内容。我正在努力寻找一种搜索全球地址列表的方法,然后
AddressEntries entries = global.AddressEntries;
AddressEntry entry = entries["search value"];
这可以工作但只返回一个实例,它是第一个找到的实例。如果有多个结果,我基本上想要向用户提供一个列表。
其次,我希望能够查看联系方式,但是当我使用
时ContactItem contact = entry.GetContact();
它总是返回null,我认为这是因为它正在查看当前用户的联系人个人列表
我想我正在尝试在Outlook中创建一个简单版本的Global Address Book窗口,如果这有意义的话。
无论如何,如果有人有任何想法或参考,我将不胜感激!
由于 帕特里克
答案 0 :(得分:4)
string[] names;
Outlook.AddressLists addrLists = Application.Session.AddressLists;
Outlook.AddressList gal = addrLists["Global Address List"];
//for a distrubution list do this...
Outlook.AddressEntry entry = gal.AddressEntries["distribution list"];
Outlook.ExchangeDistributionList exchDL = entry.GetExchangeDistributionList();
Outlook.AddressEntries addrEntries = exchDL.GetExchangeDistributionListMembers();
names = new string[addrEntries.Count];
for (int i = 0; i < addrEntries.Count; i++)
{
Outlook.AddressEntry exchDLMember = addrEntries[i];
names[i] = exchDLMember.Name;
}
return names;
//for an individual you could do something like this...
Outlook.AddressEntry entry = gal.AddressEntries["contact nickname"];
Outlook.ContactItem contact = entry.GetContact();
string name = contact.NickName;
string email = contact.Email1Address;
答案 1 :(得分:3)
您应该能够从当前个人资料中获取全局地址列表,如下所示。
Outlook.AddressLists addrLists = Application.Session.AddressLists;
Outlook.AddressList gal = addrLists["Global Address List"];
然后,您可以枚举并显示AddressList
的成员。
还有另一种方法可以解释on MSDN here。
如何:枚举中的条目 全球地址清单
答案 2 :(得分:0)
Install-Package Microsoft.Office.Interop.Outlook
using Microsoft.Office.Interop.Outlook;
var application = new Application();
AddressList gal = application.Session.GetGlobalAddressList();
if (gal != null)
{
for (int i = 1; i < gal.AddressEntries.Count - 1; i++)
{
AddressEntry addrEntry = gal.AddressEntries[i];
if (addrEntry.AddressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry ||
addrEntry.AddressEntryUserType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
{
ExchangeUser exchUser = addrEntry.GetExchangeUser();
Console.WriteLine($"{ exchUser.Name } { exchUser.PrimarySmtpAddress }");
}
if (addrEntry.AddressEntryUserType == OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
{
ExchangeDistributionList exchDL = addrEntry.GetExchangeDistributionList();
Console.WriteLine($"{ exchDL.Name } { exchDL.PrimarySmtpAddress }");
}
}
}