Reputation: 6281
How does Sharepoint retrieve the user's actual name as displayed in the top right corner? e.g Welcome John Smith
I need to call this name as a variable or parameter on custom code in the XSL editor but I can't figure out how I can retrieve it, is it a global variable?
Upvotes: 2
Views: 6001
Reputation: 687
If you want to use SPServices (which is great, btw):
function getCurrentUsersName(){
var firstName = $().SPServices.SPGetCurrentUser({
fieldName: "FirstName",
debug: false
});
return firstName;
}
function getCurrentUsersLastName(){
var lastName = $().SPServices.SPGetCurrentUser({
fieldName: "LastName",
debug: false
});
return lastName;
}
You can look up a host of other similar fieldnames here:
Upvotes: 1
Reputation: 7056
You can get a user's account name using the server variable LOGON_USER. However, this doesn't return a user's Display name.
I was able to get something working which a combination of web parts to display their name:
UserContextFilterWebPart
(you may need to enable this web part in the web part gallery).GetUserInfo
method (part of the UserGroup.asmx web service).
http://server/sites/SiteCollection/SubSite/_vti_bin/UserGroup.asmx?WSDL
GetUserInfo
for the Operation dropdown (the other dropdowns should be ok)Upvotes: 1
Reputation: 879
SPContext.Current.Web.CurrentUser.LoginName will give you the value for the login name of the current user, as displayed in the top right of a standard portal.
If you want to use this with XSLT, you need to find a way of assigning this to an XSL parameter value at run-time.
Upvotes: 0
Reputation: 818
I believe it's coming in through NTLM Authentication/Active Directory. I ususally get login name DOMAIN/User in the HttpContext.Current.User.Identity.Name field, and then match against Active Directory and bring back the actual name of the user.
Upvotes: 0