3

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'?

6 Answers 6

4

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).

5

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).

3

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

1

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

try this....

Hope this helps!

0

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

1
  • 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
    Commented Aug 16, 2012 at 19:09
0

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 "[email protected]" part between -DisplayName and -Web.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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