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

2 Answers 2


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 {})



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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.