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

让人想犯罪 __ 提交于 2019-12-06 05:42:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!