locked
Getting full name of user logged in? RRS feed

  • Question

  • I have created a .aspx page as a start page.  One of the things i am doing is trying to show in full name of the logged in user.

    I am using this control <asp:LoginName runat="server" id="LoginName1"/>

     

    Although this works to a certain degree, this is showing the users login name, for example "domainname\username"

     

    Can someone tell me how i go about just showing the Full Name of the user logged in.

     

    Many thanks.

    Tuesday, May 31, 2011 5:58 PM

Answers

  • Try this code

    SPSecurity.RunWithElevatedPrivileges(delegate() 
        { 
          using (SPSite site = new SPSite(siteURL)) 
          { 
            ServerContext serverContext = ServerContext.GetContext(context); 
            UserProfileManager profileManager = new UserProfileManager(serverContext); 
            SPUser spUser = site.RootWeb.Users.GetByID(id); 
            UserProfile profile = profileManager.GetUserProfile(spUser.LoginName); 
            string firstName = profile["FirstName"].Value;
           string 
    LastName = profile["LastName"].Value
          } 
        });

    Alternatively please refer to the following URL 

    --Cheers

    Wednesday, June 1, 2011 6:17 AM

All replies