SharePoint - Write XSLT getting icon image for attachment link

I created an event receiver in MOSS that oncreate and onupdate item, save link of Attachment in a HyperLink Field, named Link1.

So I have a list of items, with direct link to document in attachment.

In web part, I want to show Icon of type of document, in the first column.
But there is no function to get "last index of" dot, in extension of file.

So I created the script below, getting last 5 chars in link (probably, the dot and the extension, as ".pptx"):

<img src='{concat('/_layouts/images/ic',substring-after( substring(substring-before(@Link1,','),string-length(substring-before(@Link1,','))-4,6),'.'),'.gif')}' />

So, if attachment is a 'pdf' file, it search for image at url "/layouts/images/icpdf.gif".

Of course, you have all icon image in /layouts/images, or you can create your custom folder for icons!

Comments

Popular posts from this blog

Sharepoint 2010 - Filter List/Library Web Part with XSLT and Content Editor WP

Sharepoint 2010 - Multilanguage Site - Show column in current language

Sharepoint 2010 - Enable/Disable Ribbon Button with EcmaScript