-3

What logic does SharePoint use to display the login name of the current user on the user interface? In the top right corner near the ribbon SharepPoint displays the current user name, I need to know how that is achieved.

  • could you please be more specific about what exactly do you mean by current user name default. That would be helpful to clarify your doubt. – Rohit Waghela Sep 16 '16 at 14:17
0

You can use javascript to obtain users details:

//Get context and web

    ctx = new SP.ClientContext.get_current();

    var web = ctx.get_web();


    //Get user details

    **user = web.get_currentUser(); **//TO GET CURRENT USER****

    user.retrieve();


    //load the info

    ctx.load(web); 

    ctx.executeQueryAsync(onLoadSucceeded, onQueryFailed); 

    function onLoadSucceeded(sender, args) {

    //only in the success case you can work with user login

    **loginName = user.get_loginName();} //TO GET LOGIN NAME**

    function onQueryFailed(sender, args){}

Then do whatever you need to do with the variable loginName.

| improve this answer | |
  • Cool,I mean how the SharePoint default username is showing?@jasonjames – Debugger Sep 16 '16 at 14:12
0

It depends of the MemberShip provider you use. If you use the default, it automatically get the displayName of the Active Directory Account. (The user profile use the MemberShip to synch your user, and give the display name).

After on a site collection, you can find all user in the User Information List, and you will find the Display name of all the users of your site.

You can edit the value, but when the synch of profile will be launch it will overide your custom value

| improve this answer | |
  • Fine, It's make sense, I need a method used for displaying the name, Like Javascript or JSOM like that.@Nico – Debugger Sep 16 '16 at 14:58
  • You can have a look of the code of @jason james for a JSOM solution. After it depend of where you want to display it ! If your are in a SharePoint page (webpart, layout ....) the code will work. If your are in an application totaly disconected of SharePoint you need more code to get display name of a user – Nico Sep 16 '16 at 15:05

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.