how to get logged in user name with OOB?
-
Wednesday, May 09, 2012 3:12 AM
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.
Thanks
Regards
Swapna
SWAPNA
All Replies
-
Wednesday, May 09, 2012 8:25 AM
Use this
http://spservices.codeplex.com/wikipage?title=$().SPServices.SPGetCurrentUser
My SharePoint Blog
http://www.dhirendrayadav.com -
Thursday, May 10, 2012 6:25 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;
}
else
{
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,
Thanks.
Lambda Zhao
TechNet Community Support
- Marked As Answer by Jack-GaoMicrosoft Contingent Staff, Moderator Monday, May 21, 2012 2:04 AM

