Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a way to update a list's icon? I was looking to use SPList.ImageUrl, but this is read only.

The problem is that I've updated a list definition's icon; unfortunately there several list instances based on this definition already being used out there in the real world.

Is there some workaround I can use to resolve this?

share|improve this question
2  
How about extreme workaround? Go in content database, table AllList, find your list and change tp_ImageUrl field. –  Vedran Rasol Jan 31 '12 at 15:09
1  
@VedranRasol: I sincerely doubt any of our customers would be happy with us editing their content databases, and thereby possibly compromising any future support from Microsoft... Although it may be a solution for non-ISVs. :) –  Stuart Pegg Jan 31 '12 at 15:15
    
I know. That is why I used comment instead of answer and used words like extreme and workaround :) –  Vedran Rasol Jan 31 '12 at 15:18
    
Extreme -> horrifying? ;) –  Stuart Pegg Jan 31 '12 at 15:20
    
... and utterly unsupported. if MS finds out that you are changing content directly in the database they will not support the app at all –  Dave Wise Jan 31 '12 at 15:30

1 Answer 1

up vote 5 down vote accepted

Nothing in SharePoint is simple and this question proves it. I spend last hour or so on this hoping to find some remotely simple solution. (See update for SharePoint 2013 below)

ImageUrl is not a 'native' SPList property. I did some decompiling and refactoring only to find out that ImageUrl is one of the many list properties retrieved by SPListCollection class. I didn't figure out any way of updating it. I can write 2 pages on my findings but it would be useless.

So what are the other workarounds:

1. Simple image replacement

Hopefully in your original list definition you are using custom image (eg. deployed to images folder by feature). You just overwrite it with new image (using the same name). Manually, by feature, by code...

2. Using javascript

Do it on client side. Just add some javascript to your masterpage and do the switch when desired page is loaded. Here is simple example:

var listdeftype = '10000'; // List template Type from List definition
var newimgloc = '/_layouts/images/mycoollistimage.png';

if(window.location.href.indexOf("viewlsts.aspx") > -1) {
    var atags = document.getElementsByTagName('a');
    for(i=0;i<atags.length;i++){
        if(atags[i].getAttribute('id') == 'viewlist' + listdeftype ){
            var img = atags[i].getElementsByTagName("img");
            if(img[0] != null) {
                img[0].src = newimgloc ;
            }
        }
    }
}

This script replaces all list icons on All Site Content page based on your custom list definition.

3. Migration

Create new instance of list based on new list definition and then copy all items from original list.

4. Database update (not recommended)

Go in content database, table AllList, find your lists and change tp_ImageUrl field. In SP content database there is even stored procedure proc_UpdateListSettings that does the list updates. This procedure accepts @ImageUrl as parameter. This procedure is called when you do SPList.Update(). Why is ImageUrl exception (because you can set most of the list properties) is beyond my knowledge.

DISCLAIMER!

My testing environment is SP2010. Not a single workaround I listed is really useful. I deliberately didn't include all limitations and possible problems to make things more readable. I am only posting my answer because I spend some time on this issue and I want to share my findings. My only real contribution here is yet another¸proof that word simple and SharePoint cannot be used in same sentence (oh look, I did it).


EDIT: This all changed with SharePoint 2013 as Microsoft introduced a setter for SPList.ImageUrl. The MSDN description still doesn't tell you you can set the value, but you can! :-)

The following code works perfectly (look Ma, I even did it in PowerShell):

$web = Get-SPWeb https://<yourweb>
$list = $web.Lists["<ListName>"]
$list.ImageUrl = "/_layouts/15/images/itann.png?rev=23"
$list.Update()

This will update the list image to the announcements default image. Thanks Microsoft for giving us a setter.

share|improve this answer
    
Thanks for spending so much time on this. –  Stuart Pegg Feb 2 '12 at 11:01
2  
Fortunately this has changed with SharePoint 2013 as you can set the ImageUrl msdn.microsoft.com/en-us/library/… - I added the information to your post, more fame for you ;-) –  Dennis G Feb 24 at 15:16

Your Answer

 
discard

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

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