Tuesday, August 20, 2013


In this post we will discuss how we can get icon for different file types in SharePoint 2010. Also you can check out my previous posts on:

- How to get value from people picker control in infopath in SharePoint?

- Disable default email for approval workflow in SharePoint 2010 designer

- How to make date time picker read-only in InfoPath 2010?

If you are working in custom search and your search result in returning various file types like
html, pdf, excel or word etc. and you want to show a small icon for corresponding file types then this article will help you.

This function will take parameter as the itemURL and it will return corresponding icon URL. MapToIcon function of SPUtility class will give us the iconURL.

private string GetIconURL(string itemURL)
{
string iconURL = string.Empty;

iconUrl = "/_layouts/images/" + SPUtility.MapToIcon(SPContext.Current.Web, itemURL, string.Empty, IconSize.Size16);

return iconURL;
}

4 Comments: