How to show file extensions in SharePoint 2007 document lists

Someone asked me how to show file extensions in SharePoint 2007 document lists. Otherwise, you cannot tell without squinting closely at the icon (or hovering the mouse over it) whether a document is in the new or old Microsoft Office format.

image_thumb1

It was interesting to investigate, because it shows how fiddly SharePoint can be, even with what looks like a simple request. I thought perhaps I could add a column, but despite hunting through a long list, could not find one for the file extension. Then I did a hunt on Google and found advice to edit allitems.aspx or onet.xml. I figured it would be safer to create a new view, so that there is an easy way back. Here’s what I did.

First, in a Documents page  on the site I dropped down Settings and chose Create View.

image_thumb2[1]

I chose to Start from an existing view, using the default All Documents as the base.

image_thumb3

I called the view Detailed and clicked OK to save it.

image_thumb4[1]

Next, I installed SharePoint Designer 2007, which is a free download. I ran it, and opened the site by choosing File – Open Site and entering the URL of the SharePoint site. I navigated to Detailed.aspx and opened it.

The next step is to right-click over the section of the page that has the list of documents (this is a web part) and choose Convert to XSLT Data View.

image_thumb5

SharePoint Designer whirred for a moment, and then showed the web part in a slightly different format.

Now you have a couple of choices. If you want to have the extension in its own column, right-click over the Name column and choose Insert – Column to the right.

image_thumb 

Once the column is created, click in the grey header row and type a name, say Ext. Then right-click in an empty cell in the new column, and choose Insert Formula. In the formula dialog, double-click File Type which is in the Rows – Row section of the tree on the left. Click OK.

image_thumb2

Now save the modified view. If you browse to SharePoint now and select that view, you can see the file extensions.

image_thumb4

Very good; but why can’t we see the file extension as part of the file name? We can. Re-open detailed.aspx in SharePoint Designer. Delete the Ext column. Right-click a cell in the Name column in the web part and choose Edit Formula. Currently it looks like this:

ddwrt:UrlBaseName(string(@LinkFilename))

We need to modify this to show the file extension. Now, in case you are wondering, the ddwrt namespace is documented here; it does not turn up if you search Help in SharePoint Designer. The formulas are documented here; they don’t show up in Help either. So  UrlBaseName is a function that strips the file extension, while LinkFileName is mysteriously described thus:

Returns a GUID that represents the icon that is used to create a link to a file in a document library, where the file can be edited by using a menu.

If you simply remove the UrlBaseName function you will get the full filename:

string(@LinkFilename)

image_thumb7

You could also use the formula @FileLeafRef – the result is exactly the same. FileLeafRef is documented just as mysteriously:

Returns a GUID that represents information about the server-relative URL for the file node that is associated with the specified Windows SharePoint Services object.

Still, maybe there is some good reason why LinkFileName was used in the original formula.

Note that you can make Detailed.aspx the default view if you wish. Just edit the view in SharePoint and check the option to Make this the default view.

Helpful post? Sponsor ITWriting.com for ad-free access to the site

VN:F [1.9.18_1163]
Rate this post
Rating: 10.0/10 (5 votes cast)
How to show file extensions in SharePoint 2007 document lists, 10.0 out of 10 based on 5 ratings

2 comments to How to show file extensions in SharePoint 2007 document lists

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>