how to get logged in user name with OOB? RRS feed

  • Question

  • Dear All,


    i need to prepopulate the login user name in newform.aspx. Pleasse tell me how to do it with OOB or Jquery/java scripe.we re using standard edition,we can't use infopath form.





    Wednesday, May 9, 2012 3:12 AM


  • Hi swapna_l9

    You can create a web part which can get the login user name and add this web part to the newform.aspx. You can get user info by writing code like this:

    SPContext currentContext=SPContext.Current;

    string uName=string.Empty;

    if (currentContext != null && currentContext.Web.CurrentUser != null)


            SPWeb web = SPControl.GetContextWeb(currentContext);       

            uName = web.CurrentUser.LoginName;




            uName = System.Web.HttpContext.Current.User.Identity.Name;


    After writing the web part, you can add querystring toolpaneview=2 to the newform.aspx url like this:

    http://sitename/Lists/Tasks/NewForm.aspx?RootFolder=%2FLists%2FTasks&source=http%3A//lambda2007/default.aspx&toolpaneview=2 to add the new web part.

    You can either use JQuery to send an ajax request to the url

    http://sitename/_layouts/userdisp.aspx?Force=True, and use Regex to search the information you need about the user.

    RegExp("FieldInternalName=\"" + “Name” + "\"", "gi")

    Hope that helps,


    Lambda Zhao

    TechNet Community Support

    Thursday, May 10, 2012 6:25 AM

All replies