Joh*_*nny 14 c# exchange-server exchangewebservices
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.
Bre*_*yan 12
这是如何使用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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经无视创建verbocity服务,请查看Exchange Web服务API以获取更多信息.