Display Document Type Icon in a DVWP

I had a requirement to display document icons inside a Data View Web Part. While googling I found some interesting information on this document types and there icons.

SharePoint has a pre populated list of document types along with respective images that maps to it. This document type to document icon image mapping can be found inside the file DOCICON.XML which can be located in the following location  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML

So now how to display the document type icons inside a DVWP. If you have worked with DVWP then you already know there is a names space DDWRT that has quite a lot pre defined functions. Inside those DDWRT function you will find ddwrt:MapToIcon that can be used to get the respective image for a given document type.


<img alt="Type" src="/_layouts/images/{ddwrt:MapToIcon('', ddwrt:GetFileExtension(string(@FileLeafRef)))}"/>


In this case we are using another ddwrt method to get the file extension from the file leaf ref and processing it to get the image.

That’s it Smile


2 thoughts on “Display Document Type Icon in a DVWP

  1. Thanks for this. One thing I note that if you have a folder – ie no extension it gives the generic blank document icon.


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s