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