开发者

Retrieving User Name in Sharepoint?

开发者 https://www.devze.com 2023-01-19 06:42 出处:网络
How does Sharepoint retrieve the user\'s actual name as displaye开发者_StackOverflowd in the top right corner? e.g Welcome John Smith

How does Sharepoint retrieve the user's actual name as displaye开发者_StackOverflowd 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?


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:

  1. Add a UserContextFilterWebPart (you may need to enable this web part in the web part gallery).
  2. Add a DataView webpart which queries the GetUserInfo method (part of the UserGroup.asmx web service).
    • a. Click "Connect to a web service..." in the Data Source Library pane under XML Web Services
    • b. Enter the Service description location (the URL to the UserGroup web service). Ex: http://server/sites/SiteCollection/SubSite/_vti_bin/UserGroup.asmx?WSDL
    • c. Click Connect (or reconnect)
    • d. Choose GetUserInfo for the Operation dropdown (the other dropdowns should be ok)
    • e. Modify the userLoginName parameter and check the box to allow the value to be set via web part connection. I also added a default value to test (ex: domain\login).
    • f. Click OK.
    • g. Click on the data source and click Show Data
    • h. Choose the columns you need and then drag them onto the page
  3. Connect them together using web part connections (UserContext provided to the DataView).


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:


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消