问题
Exchange Autodiscovery will give me the user's Display Name via the UserSettingName.UserDisplayName
property.
However, in cases where autodiscovery fails and connection needs to be done manually I can't figure out how to get the DisplayName.
I tried this, but I just get the users' email address:
_service = new ExchangeService();
_service.Credentials = new System.Net.NetworkCredential(exchangeSettings.EmailAddress, exchangeSettings.Password);
_service.Url = new Uri(exchangeSettings.ExternalEwsUrl);
NameResolutionCollection resolvedNames = _service.ResolveName(exchangeSettings.EmailAddress);
exchangeSettings.UserDisplayName = resolvedNames.First().Mailbox.Name;
Thanks
回答1:
If you are going to use ResolveName
and you want the displayName then you should use the overload to specify that the operation should return the AD contact information. Then you can just use the DisplayName
property.
NameResolutionCollection ncCol =
service.ResolveName("user@domain.com",ResolveNameSearchLocation.DirectoryOnly,true);
Console.WriteLine(ncCol[0].Contact.DisplayName);
来源:https://stackoverflow.com/questions/8330515/how-do-i-get-the-displayname-of-the-logged-in-user-in-ews