As Sharepoint is used more and more as a BI platform, a lot of different solutions get hosted on SP pages. But how can you plug into SP's user identification and use it for your own code?
Here's a quick and dirty approach I unearthed while squeezing some Silverlight onto a SharePoint page.
The basic idea:
*In SharePoint Designer, open up the page you’ll be using
*Drop a list (any list) web part onto the page; convert the list to an XSL data view
*Add a system variable for the current user (I used LOGON_USER)
To do this, find the section of the page where “ParameterBinding”s are set. Add a new row that looks like this:
<ParameterBinding> Name = “LogonUser” Location = “ServerVariable(LOGON_USER)” />
Next, look for the area where parameters are defined by searching for the string “XSL:Param name”, and add this line:
<xsl:param name="LogonUser"/>
*Drop that variable in a cell within the data view which is named something you can recognize later, and hide it
<table border="0" cellspacing="0" width="100%">
<tr style="display:none">
<td id="MagicalUserPerson" width="400px" valign="top" class="ms-formbody">
<xsl:value-of select="$LogonUser"/>
</td>
</tr>
</table>
Now you can reference the cell “MagicalUserPerson” in your code elsewhere.
Here's a bit more of a walkthrough, including an explanation of what other user variables you might choose to work with:
Getting the Current User Name or ID in SharePoint using SharePoint Designer (no code)
No comments:
Post a Comment