谁能告诉我从Exchange Server获取联系人列表的最简单方法?我正在使用C#

据我了解, Exchange Web服务仅存在于Exchange Server 2007及更高版本中。那将是我的第一个选择,但我也想为以前版本的Exchange(WebDav或其他版本)提供替代方案。目录服务不是一个选择。

最佳答案

这是使用EWS交换时从联系人列表中获取联系人列表的方法。我还不确定如何从全局列表中获取联系人,只是一个小时前才看过API。

private static void ListContacts(ExchangeService svc) {
    foreach (var v in svc.FindItems(WellKnownFolderName.Contacts,
                                    new ItemView(20))) {
        Contact contact = v as Contact;
        ContactGroup contactGroup = v as ContactGroup;

        //v.Load(); // Turns out you don't need to load for basic props.
        if (contact != null) {
            Console.WriteLine("Contact: {0} <{1}>",
                contact.DisplayName,
                contact.EmailAddresses[EmailAddressKey.EmailAddress1]);
        } else if (contactGroup != null) {
            Console.WriteLine("Contact Group: {0}", contactGroup.DisplayName);
            switch (svc.RequestedServerVersion) {
                case ExchangeVersion.Exchange2007_SP1:
                    ExpandGroupResults groupResults
                        = svc.ExpandGroup((contactGroup.Id));
                    foreach (var member in groupResults) {
                        Console.WriteLine("+ {0} <{1}>",
                            member.Name, member.Address);
                    }
                    break;
                case ExchangeVersion.Exchange2010:
                    foreach (GroupMember member in contactGroup.Members) {
                        Console.WriteLine("+ {0} <{1}>",
                        member.AddressInformation.Name,
                        member.AddressInformation.Address);
                    }
                    break;
                default:
                    Console.WriteLine(
                        "** Unknown Server Version: {0}",
                        svc.RequestedServerVersion);
                    break;
            }
        } else {
            Console.WriteLine("Unknown contact type: {0} - {1}",
                contact.GetType(), v.Subject);
        }
    }
}

我已经省略了为语音服务的创建,请查看Exchange Web Services API以获取更多信息。

关于c# - 如何从Exchange Server获取联系人列表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2071668/

10-13 06:49