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

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

| improve this answer | |
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).

| improve this answer | |
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

| improve this answer | |
1

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

try this....

Hope this helps!

| improve this answer | |
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

| improve this answer | |
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 "user@domain.com" part between -DisplayName and -Web.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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