tig
tig

Reputation: 3483

How do I get the displayname of the logged in user in EWS?

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

Upvotes: 4

Views: 3552

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

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("[email protected]",ResolveNameSearchLocation.DirectoryOnly,true);

Console.WriteLine(ncCol[0].Contact.DisplayName);

Upvotes: 7

Related Questions