Skip to content

SPWeb.ListTemplates doesn’t include custom list templates

December 10, 2010

You have a list template stp file uploaded in the List Template Gallery and you want to access it by code. The first idea is probably to check the ListTemplates property of your SPWeb but this will not contain your custom list template even if the documentation suggests it does.:

Gets the collection of all list definitions and list templates that are available for creating lists on the Web site.

If you give it a try you will get only the OOB list definitions:

foreach (SPListTemplate lt in site.RootWeb.ListTemplates)

Document Library
Form Library 
Wiki Page Library 
Picture Library 
Discussion Board 
Project Tasks 
Custom List 
Custom List in Datasheet View 
Workflow History 
Site Membership Review List 
Custom Workflow Process 
No Code Workflows 

What you need to do is to call the GetCustomListTemplates() method of the SPSite

SPListTemplateCollection listTemplates = site.GetCustomListTemplates(site.RootWeb);

 That will give you the list templates that are uploaded in your List Template Gallery.

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: