views:

268

answers:

1

Is it possible to find, in a Web Part, if a list is made from a specific content type? Or, find all lists that are from a specific content type would do the trick too!

+1  A: 

You need to get a handle to the specific list first, of course. There's a number of ways to do this. A somewhat inefficient, but globally usable way, would be to start from the SPSite:

using(SPSite site = new SPSite(siteUrl))
{
    using(SPWeb web = site.OpenWeb(webUrl))
    {
        SPList list = web.GetList(listUrl);
        SPContentTypeCollection types = list.ContentTypes;
        foreach(SPContentType type in types)
        {
            if(type.Id == typeImLookingFor.Id)
            {
                //found the content type!
            }
        }
    }
}
Rex M
It was easy.. weird that I didn't find anything on Google. Thanks! :)