none
Get Name of User from Active Directory RRS feed

  • Question

  • I need to show only the name of a user from active directory, i am using

     lbl_Login.Text = User.Identity.Name; //the result is domain\username

    this shows the users name but not the real name of the user, i've checked other questions and answers related here but i've not gotten the solution.

    Is there any property just as "User.Identity.Name" to get only the name of the user?

    Thanks

    Monday, August 29, 2016 8:56 PM

Answers

All replies

  • Hello,

    You can use classes from the following namespace (assembly):

    System.DirectoryServices.AccountManagement

    using (var pc = new PrincipalContext(ContextType.Domain, "MyDomainName"))
    {
        var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "MyDomainName\\" + userName);
    }

    See How to get a username in Active Directory from a display name in C#? for more information.


    [custom.development]

    Monday, August 29, 2016 10:57 PM
  • Hi Hanspam,

    first I want to confirm with you that in which project type you are developing?

    is it Word document, Addin or Templet?

    you are using word.interop? or you are trying to use any other .net component?

    also if possible please trying to clear what you want to achieve by getting username from active directory?

    you had only post one line of code which is not enough to understand the actual issue.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, August 30, 2016 12:53 AM
    Moderator