Quantcast
Channel: Development With A Dot
Viewing all articles
Browse latest Browse all 404

Retrieving SharePoint User Profile Properties in XSLT

$
0
0

A common request is to be able to retrieve user information from XSLT (XsltListViewWebPart, DataFormWebPart, etc). It is possible to obtain some information through server variables (LOGON_USER), CAML variables (UserID) or ddwrt:UserLookup extension function. It works, to some extent, but sometimes it is not enough.

It is well known that one can have server controls in XSLT stylesheets. As it happens, the ProfilePropertyValue control retrieves any value from the user profile. It just needs to have a ProfilePropertyLoader declared before it, which can be placed in the master page. For example:

   1:<SPSWC:ProfilePropertyLoaderLoadFullProfileOfCurrentUser="true"runat="server"/>
   2:<SPSWC:ProfilePropertyValuePropertyName="FirstName"ApplyFormatting="false"runat="server"/>

Just remember to register the Microsoft.SharePoint.Portal.WebControls assembly with the SPSWC tag prefix, either in the Web.config or in the page itself.

But, what about XSLT? Well, if the SPSWC tag prefix is registered in Web.config, we can do this:

   1:<xsl:templatename="GetProfilePropertyValue">
   2:<xsl:paramname="Property"/>
   3:<SPSWC:ProfilePropertyValuePropertyName="{$Property}"ApplyFormatting="false"runat="server"/>
   4:</xsl:template>
   5:  
   6:<xsl:variablename="Property">WorkEmail</xsl:variable>
   7:  
   8:<xsl:variablename="WorkEmail">
   9:<xsl:call-templatename="GetProfilePropertyValue">
  10:<xsl:with-paramname="Property"value="$Property"/>
  11:</xsl:call-template>
  12:</xsl:variable>
  13:  
  14: Work Email: <xsl:copy-ofselect="$WorkEmail"/>

With this technique, you can retrieve any of the profile properties. Ah, don’t forget to add:

   1: xmlns:spswc="Microsoft.SharePoint.Portal"

To the <xsl:stylesheet> declaration.

Happy SharePointing! Winking smile





Viewing all articles
Browse latest Browse all 404

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>