Getting A Specific SPListTemplateType Icon

MORE INFO: To answer a question I received about this, if you have a hydrated SPList you can use the SPList.BaseTemplate property as a reasonable parameter.

Unfortunately, I haven’t found a *good* way to do this. You are basically forced either to put in a grip of if statements (yuck!) or just put in a simple switch/case. Since it is boring to look up all the image names in the 12 hive, I will make your live easier for you. Just use this helper method which will consume a SPListTemplateType as a parameter. Following, it will recur through and return a string providing the path to the list icon in order to support your interface needs.

[csharp]
public static string RetrieveListIcon(SPListTemplateType type)
{
switch (type)
{
case SPListTemplateType.DocumentLibrary:
return “/_layouts/images/itdl.gif”;
case SPListTemplateType.Announcements:
return “/_layouts/images/itann.gif”;
case SPListTemplateType.Events:
return “/_layouts/images/itevent.gif”;
case SPListTemplateType.Links:
return “/_layouts/images/itlink.gif”;
case SPListTemplateType.Tasks:
return “/_layouts/images/ittask.gif”;
case SPListTemplateType.DiscussionBoard:
return “/_layouts/images/itdisc.gif”;
case SPListTemplateType.PictureLibrary:
return “/_layouts/images/itil.gif”;
case SPListTemplateType.IssueTracking:
return “/_layouts/images/ITISSUE.GIF”;
default:
return “/_layouts/images/itgen.gif”;
}
}

[/csharp]

Share

One Comment

  1. Saikat Biswas says:

    Few more from my side…

    public static string RetrieveListIcon(SPListTemplateType type)
    {
    switch (type)
    {
    case SPListTemplateType.DocumentLibrary:
    return “/_layouts/images/itdl.gif”;
    case SPListTemplateType.Announcements:
    return “/_layouts/images/itann.gif”;
    case SPListTemplateType.Events:
    return “/_layouts/images/itevent.gif”;
    case SPListTemplateType.Links:
    return “/_layouts/images/itlink.gif”;
    case SPListTemplateType.Tasks:
    return “/_layouts/images/ittask.gif”;
    case SPListTemplateType.DiscussionBoard:
    return “/_layouts/images/itdisc.gif”;
    case SPListTemplateType.PictureLibrary:
    return “/_layouts/images/itil.gif”;
    case SPListTemplateType.IssueTracking:
    return “/_layouts/images/ITISSUE.GIF”;
    case SPListTemplateType.Survey:
    return “/_layouts/images/itsurvey.GIF”;
    case SPListTemplateType.WorkflowProcess:
    return “/_layouts/images/ITWFH.PNG”;
    case SPListTemplateType.TextBox:
    return “/_layouts/images/ITTXTBOX.GIF”;
    case SPListTemplateType.Agenda:
    return “/_layouts/images/ITAGNDA.GIF”;
    case SPListTemplateType.Categories:
    return “/_layouts/images/ITCAT.GIF”;
    case SPListTemplateType.Comments:
    return “/_layouts/images/ITCOMMNT.GIF”;
    case SPListTemplateType.Contacts:
    return “/_layouts/images/ITCONTCT.GIF”;
    case SPListTemplateType.DataSources:
    return “/_layouts/images/ITDATASH.GIF”;
    case SPListTemplateType.Decision:
    return “/_layouts/images/ITDECIS.GIF”;
    case SPListTemplateType.Posts:
    return “/_layouts/images/ITPOSTS.GIF”;
    case SPListTemplateType.MasterPageCatalog:
    return “/_layouts/images/itdl.gif”;
    case SPListTemplateType.WebPartCatalog:
    return “/_layouts/images/itdl.gif”;
    default:
    return “/_layouts/images/itgen.gif”;
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *