This article explains how you can configure icons for files in SharePoint. But what if you want to reuse these icons for custom links that your solution (e.g. webpart) generates. Is there a smart and easy way to read these Mappings to determine icon for each URL pointing to a file?


Yes, it is possible and an API exists to help you!

SPUtility's following method can retrieve the value of the icon for the file (or file extension) that you specify in input parameter.

public static string MapToIcon(
    SPWeb web,
    string strFileName,
    string strProgID,
    IconSize size

Notes: 1. The returned value is based on the mapping between file extension and corresponding icon that exists in {SharePointRoot}\TEMPLATE\XML\DOCICON.XML

  1. Icon needs to be present in {SharePointRoot}\Template\Images folder

The value that you might be interested would be /_layout/images/[Returned Value of above function]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.