6

我正在开发一个应用程序,允许用户用户查看他们有权访问的收件箱的内容。我很难找到一种搜索全球地址列表的方法

AddressEntries entries = global.AddressEntries;
AddressEntry entry = entries["search value"];

这有效,但只返回一个实例,它是找到的第一个实例。如果有多个结果,我基本上想向用户提供一个列表。

其次,我希望能够查看联系方式,但是当我使用

ContactItem contact = entry.GetContact();

它总是返回null,我认为是因为它正在查看当前用户的联系人个人列表

如果有意义的话,我想我正在尝试在 Outlook 中创建一个简单版本的全局通讯簿窗口。

无论如何,如果有人有任何想法或参考,我将不胜感激!

谢谢帕特里克

4

3 回答 3

5

您应该能够从当前配置文件中获取全局地址列表,如下所示。

Outlook.AddressLists addrLists = Application.Session.AddressLists;
Outlook.AddressList gal = addrLists["Global Address List"];

然后您可以枚举并显示 that 的成员AddressList

在 MSDN here 上描述了另一种方法来执行此操作。

如何:枚举全局地址列表中的条目

于 2010-11-18T01:19:52.020 回答
5
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;
于 2012-02-08T16:04:01.223 回答
0
  1. 安装 Outlook 互操作包Install-Package Microsoft.Office.Interop.Outlook
  2. 这是代码(取自 MSDN)
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 }");
                    }
                }
            }
于 2021-04-12T12:08:05.453 回答