SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to change document icon in document library at runtime. Icon should be changed based on some condition I have in code. There is no difference what extension of file is (txt, doc, pdf, etc..). Currently I use HTTP module to parse server response and change icon in runtime. However this solution is not reliable as page HTML markup may be changed, different views has different behavior and there are issues with registration HTTP module in SharePoint 2010. Is there any API or any other reliable way to change document's icon at runtime?

I would appreciate any help. Thanks beforehand, -Petro

share|improve this question

There are two approaches that I would use, both applied client side. However, since you state that regardless of which doc type icon is displayed in the results you want to replace it with a single doc type image, you really only need the one approach...

Use CSS. The doc icon in a list view web part has its own class ("vb-type" I think, but it's been a while since I've style a list view web part) which you can use in CSS to override. You would specify that the doc type image be display:none, and you would specify the background image for that class should be whatever icon image you want to display for list items.

To trigger whether this replacement should occur or not, make the "condition [you] have in code" write a class name (e.g. class="replaceIcons") to the table that displays the document list items or wrap that table in a div with a class name applied to the div. Then in your CSS you can use that class name as a specifier in your rule (e.g. .replaceIcons td.vb-type {})

share|improve this answer


I am sure that jQuery library can rescue you here :)

Refer to jQuery - Enhancing List View Rendering

I am sure this will give you some pointers :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.