Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can anyone tell me the simplest way to get a contact list from Exchange Server? I'm using C#

From what I found out, Exchange Web Services only exists for Exchange Server 2007 and beyond. That would be my first option, but I'd also like an alternative for previous versions of Exchange (WebDav or something). Directory Services is not an option.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
253 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is how to get the contact list from your contacts list in exchange using EWS. I'm not sure how to get contacts from the global list yet, only looked at the API an hour ago.

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);
        }
    }
}

I've ommited creating the service for verbocity, have a look at the Exchange Web Services API for more information.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...