How do I get the File Extension in my Search Results?

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…

The Search Results page showing XML

…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:

The Selected Columns Setting in a Web Part Toolbox view

And opening this for editing shows a bunch of columns being selected:

Selected  columns dialog window

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:

Selected Columns Dialog with File Extension Added

And the results now showed:

Search XML from Query, with File Extension information.

Great! And the values are consistently capitalised! Hurray! Now I can use it in my styling…

Advertisement
How do I get the File Extension in my Search Results?

2 thoughts on “How do I get the File Extension in my Search Results?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.