How to get the display name of the registered user in EWS?

Exchange Autodiscovery will provide me with a display username using the UserSettingName.UserDisplayName property.

However, in cases where autodiscover fails and the connection needs to be completed manually, I cannot figure out how to get DisplayName.

I tried this, but I just got 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

+4
source share
1 answer

If you intend to use ResolveName , and you need the name displayName, you must use overloading to indicate that the operation should return 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); 
+5
source

Source: https://habr.com/ru/post/1383941/


All Articles