Monday 12 January 2009

Using SPUtility.MapToIcon to retrieve an item's icon based on the item type

In a SharePoint web part project, when you need to display an item's icon based on it's item type, "SPUtility.MapToIcon" can be used to return the item's icon:

SPUtility.MapToIcon(SPContext.Current.Web, zItemURL, string.Empty, IconSize.Size16)

Pass in the item's URL (or file extension) and "MapToIcon" returns a string value of the icon for that file extension, based on the icon specified in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\DOCICON.xml". The icon file needs to reside in the folder "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES".

e.g.

zImageUrl = "/_layouts/images/" + SPUtility.MapToIcon(SPContext.Current.Web, zItemURL, string.Empty, IconSize.Size16)

1 comment:

  1. I wish I had seen this last night!
    http://whoisidaho.com/wordpress/?p=184

    ReplyDelete