Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to retrieve the display name('firstname lastname') of a user who logs in the SharePoint site.

When I log into my SharePoint site I could see at the top right --'domain/user name'. So when I try to retrieve the display name of the user using SharePoint object model (item adding event receiver)

SPWeb web = properties.OpenWeb();
var strCurrentUser = web.CurrentUser.Name; or var strCurrentUser = web.CurrentUser.LoginName;  

In both the cases strCurrentUser gives out 'domain/user' name.

Is there any way that i can get the full user name instead, like 'first-name last-name' or 'domain/first-name last-name'?

share|improve this question
add comment

6 Answers

up vote 4 down vote accepted

The SPUser object (SPContext.Current.Web.CurrentUser) does have a Name property, but it may not be filled out. If not, you may need to resort to going against the user profile ( http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofile(v=office.12).aspx ), but that is only available in Server (not Foundation).

share|improve this answer
add comment

I am having this problem all the time. Some users are showing up fine with full name (automatically filled from Active Directory), but others show only login name instead (domain\user). Still have not found the solution to this, neither the reason why it is happening.

However! I did find a very quick workaround to fix the name of certain users.

  1. Open SharePoint Management Shell (Start > type "Manage..." it will show up).

  2. Type and enter this line:

    Set-SPUser -Identity domain\user123 -DisplayName "James Cook" -Web http://SpServerHostName

  3. Done! All of a sudden, domain\user123 will show up as Jame Cook everywhere. As well as wherever you use SPUser.Name.

P.S. To update missing E-mail of user, add -Email "user@domain.com" part between -DisplayName and -Web.

share|improve this answer
add comment

Check out this url, you can get first name last name in this way http://www.fewlines4biju.com/2011/04/how-to-get-userprofile-information.html

share|improve this answer
    
While this may theoretically answer the question, we prefer inclusion of the essential parts of the answer here, and to provide the link for reference. See answer for general guidelines.Also we require disclosure of any affiliation with products or websites. Please see May I promote products or websites I am affiliated with here? for guidelines. –  SPDoctor Aug 16 '12 at 19:09
add comment

UserProfile userProfile = GetUserInformation(user); string fullName= userProfile[PropertyConstants.AccountName].Value.ToString();

try this....

Hope this helps!

share|improve this answer
add comment

You need to have user's first and last name in SharePoint User Profile Service Application in order to see 'firstname lastname'.

Try modifying User Profile of your test user: add first and last name. Then log out and back in and you should see the correct name.

If that works, update other users as well (by setting up user profile synchronization).

share|improve this answer
add comment

if you do not use user profile service, you can go to site actions -> site permissioms. There are users and groups that have access to your site. In this list you can click on a user name and see it's details. In ribbon on details view you can click on Edit button and set Name property of this user. after this you can retrieve it by SPUser.Name

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.