You must Sign In to post a response.
  • Category: Sharepoint

    Display logged in user details in SharePoint 2013

    Hi Guys,

    I am new in sharepoint development. My requirement is I need to display logged in user details in sharepoint 2013 without using C# code. I am struggling on this last one week. Please guide me the easiest way to achieve this.

    Thanks in Advance,
    Simiyon A
  • #762835
    Hi simiyon,

    If you want to show logged in user name then use below line of code.


    SPContext.Current.Web.CurrentUser;

    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762838
    Hello Simiyon,

    I am agreed with Mr. Navin's answer.

    You can do it by JQuery also :

    (function($){

    $(document).ready(function(){
    // Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
    SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');
    });

    var userProfileProperties;

    function loadUserData(){

    //Get Current Context
    var clientContext = new SP.ClientContext.get_current();

    //Get Instance of People Manager Class
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    //Get properties of the current user
    userProfileProperties = peopleManager.getMyProperties();

    clientContext.load(userProfileProperties);

    //Execute the Query.
    clientContext.executeQueryAsync(onSuccess, onFail);

    }

    function onSuccess() {

    alert(userProfileProperties.get_displayName());

    }

    function onFail(sender, args) {
    alert("Error: " + args.get_message());
    }

    })(jQuery);


    It will show you the output or error in alert box.


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


  • Sign In to post your comments