After seeing my post on displaying recent blog posts from around a SharePoint site a pal (@andrewjolly) got in touch and asked me if it would be possible to display a user’s photo via XSL. After digging around I found that there are a few different scenarios where this could be used with different approaches for each:
- A data view web part (DVWP)
- A content query web part (CQWP)
- Or in customised search results
This post details one possible way of doing this in the data view web part (thanks to Ben for the advice).
In SharePoint Designer (SPD) if you add in a data source to a page and point it at a regular SharePoint list or library you will see the options to insert the data and the available fields like so:
You’ll notice here that there is no field returned with the user’s profile photo value in it. However, it is possible to get it there! Remember that the presentation of a user column can be modified through the browser, and some of these presentation styles include the user’s photo. To do this, navigate to the list or library in question, edit the settings for the list and then go on to edit the settings for the specific column. You’ll see an option to change the presentation of the column like so:
If you change this from the default value of Name (with presence) to an option with an image, say Name (with picture) and then go back into SPD and refresh your data source you’ll now see that the picture value is available in a field (in this case the field Author.picture):
This field can then be accessed in the XSL and it’s a fairly straight forward job to use this data as required, i.e. set an image tag to use it as its source or just output the path.
It’s interesting to note that the ‘availability’ of this field doesn’t appear to be an SPD rendering thing – which was my first suspicion (I spent a while reading through the ‘code’ to try and find the expandfields flag – or whatever – with no success). But actually it seems that the datasource is reading directly from the columns in the list and it is these columns are determining the data that can be displayed. Which I suppose is obvious when you think about it.
So as a warning, if the settings on the column in your list are changed to not include the picture then your data view web part will no longer return this as a value.