Following on from my previous post, I’ve been looking some more at the code that one of my colleagues has created for styling up some search results. In it he needs the file extension for the item resulting, and he does this by, um, assuming that it’s the last 3 letters of the items URL. Yes, I am not amused. For example, if you look at the results from my last post…
…you may notice that the final 3 letters are ocx – because it’s a .DOCX file. Worse, these can be of different cases, and that is what has me looking at all of this in the first place.
Well, I simply couldn’t believe that file extension wasn’t available in the XML – but from what I’d seen so far, it wasn’t. However, looking at the Search Core Results web part, I noticed it has a ‘Selected columns’ setting in the “Results Query Options” section:
And opening this for editing shows a bunch of columns being selected:
These seemed to match my results fairly closely. Is there a FileExtension column?
Well, yes, as it turns out. I found this in the SharePoint Search XSL Samples on Codeplex. The installation instructions for the File Extension Pivot sample mention adding a column…
<Column Name="FileExtension" />
So I added this to my selected columns:
And the results now showed:
Great! And the values are consistently capitalised! Hurray! Now I can use it in my styling…
2 thoughts on “How do I get the File Extension in my Search Results?”
[…] a previous post I described adding the FileExtension column to the XML you get back from a SharePoint search, so that you can use it in your results page. This raises the question – what columns are available […]
[…] Reader opens and automatically searches for occurances of the search term. Doing this requires knowing your file extension (so you only process PDFs this way), knowing the query string parameter for what is being searched […]