3e Replace Cryptic Filename with Title in SharePoint 2007 Library 48
Posted by 9 Sean Ryan 8 4e3 Feb 31 2 15 4d
I’ve read many posts related to a request to show a linked Title field. The title can contain a friendly name rather than the actual file name. Often in the libraries I will see CX3000_x3_DiffDeptRpt.pdf rather than Coaxial Cable Differences Report. I like the second better myself and non technical every day users abhor the first. Regularly the answers supplied relate to why you’d even want to make this change. Let’s assume you do. It can be done.
This relates to SharePoint Designer 2007.
First, Create a Standard View from your document library page and make sure Title is among the visible fields. Do not group or Filter.
Open the site in SharePoint Designer 2007 and locate the view you created.
Open in Design view.
Highlight the Main area where the listing shows WebPartPages:ListViewWebPart will show.
Right click and choose Convert to XSLT Data View.
Save.
Still in Design view, look to the top of the listing and click the td where your file name resides.
Click the small right arrow that appears next to a file name. The Common xsl:value-of Tasks dialog shows. It will likely contain Data Field: @LinkFilename with Format as: Text. We’re going to change this.
Click the Data Field drop down and choose @Title.
Click the Format as drop down and choose Hyperlink.
In the Edit Hyperlink dialog, you will see {@Title} in the Text to display area and also in the address area. Click the function (fx) button next to the Address field.
You are presented with the More Fields dialog. Scroll down to URL Path. This equates to the XPath value of @FileRef. There appears to be a bug next. It creates the code for you except it doesn’t quite finish it.
View the page in Split view. Click on the area where the file name is and find the hyperlink a href and fix it to read:
<a href="{@FileRef}"><xsl:value-of select="@Title" /></a>
Save the page and open the browser. This will place the Title in that spot. Nice.
Not done quite yet…
The next thing you will need to do is assume that somebody will not use Title (whether we should require it is another topic). So, in the code view add the following code.
Note: The first line is the one we just edited, so start at
<a href="{@FileRef}"><xsl:value-of select="@Title" /></a>
<xsl:choose>
<xsl:when test="@Title=''">
<a href="{@FileLeafRef}"><xsl:value-of select="@FileLeafRef" /></a>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
Now, edit one of your documents and remove the Title. The real file name should show as it would have before.
Good luck.
56







