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 FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEXML

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


  • Excellent article, and saved us tons of development efforts
    Thank you

  • Ian.buckland@downer.co.nz says:

    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 to Usman Cancel reply

Your email address will not be published. Required fields are marked *