Show File Extension in Sharepoint Document Library
January 21, 2014 in RandomI was recently tasked with changing the view in our TFS Project Portal’s document library to show the file extension so you knew whether you were opening a PDF, Word Document, PowerPoint or something else for which you might not have the software installed. There is an easy way and a hard way, and the guidance I received from a few Google searches skipped a few steps on the hard way.
Easy Way
- Open the Document Library
- Click on the Library Tools -> Library tab at the top
- Scroll to the bottom and click the view you wish to change
- Check "Name used in forms" column
This adds a new column with the full file name and extension, but it’s not clickable to view the document, so you end up with two columns for document name, the name and the name with extension. This is why I ended up going down the hard way.
Hard Way
- Open the site in SharePoint Designer
- Click Lists and Libraries and open the Document Library you want to modify
- Open the View you want to modify
- Right click on the first row in the Name column and select Insert Formula
- In the Edit XPath expression box enter something that is easily searchable ie. xxxxxxxx
- Click OK
- Switch to the Code View
- Search for your xxxxxxx and delete the element it created
- Right above or below that should be an element like so <xsl:value-of select="$thisNode/@FileLeafRef.Name" />
- Replace that with <xsl:value-of select="$thisNode/@FileLeafRef.Name" /><xsl:if test="$thisNode/@FileLeafRef.Suffix!=''">.<xsl:value-of select="$thisNode/@FileLeafRef.Suffix" /></xsl:if>
- Save, exit and you're done
The examples I found online left out steps 4-8, and until I did those the <xsl:value-of select=”$thisNode/@FileLeafRef.Name” /> element didn’t exist.
Have a comment or suggestion? This blog takes pull requests.Or you can just open an issue.