When customizing Data View Web Parts (DVWPs) in SharePoint Designer, the field FileRef can be used to get the URL of an item. While most list items would be displayed by sending the user to a page containing a List Form Web Part in “Display” mode (e.g. DispForm.aspx), it can sometimes be useful to send the user directly to the item itself, especially in cases of Document Libraries.
In SharePoint 2007, the FileRef field value is provided as a server-relative url. Therefore, a reliable link to the list item could be established by setting the href attribute of an anchor tag to the FileRef field value like so:
In such an example, the href attribute value could be something like (note: FileRef field value underlined):
However, SharePoint 2010 provides this field value as a psuedo server-relative URL (for lack of a better term); it does not include the initial forward slash generally used to distinguish the server-relative nature of a URL, therefore providing a relative URL. The href attribute could thus be something like (note: FileRef field value underlined):
This subtle difference could break many a DVWP should the environment ever be upgraded from SharePoint 2007 to SharePoint 2010. While such an issue is easy to resolve, manually updating each DVWP just before or after the upgrade process would be tedious and unreliable. Instead, it would be much easier to preemptively include handling for both environments like so:
<xsl:if test=”substring(@FileRef, 1, 1) != ‘/’”>
<xsl:value-of select=”concat(‘/’, @FileRef)” />
<xsl:value-of select=”@Name” />
Alternatively, an xsl:choose element could be used to accomplish this resolution.