SharePoint 2010: GetAvailableWebTemplates CollectionNotInitializedException

The new client object model is something which required some getting used to. Most of the data in the objects isn’t loaded untill you request it, even when calling methods.

For instance, the method GetAvailableWebTemplates returns an object of type WebTemplateCollection. You would probably expect that object to contain all the available web templates on your site, right? Well it doesn’t, untill you’ve explicitely ordered the ClientContext to load that collection. So what you want to do is:

WebTemplateCollection coll = rootWeb.GetAvailableWebTemplates((uint)language, false);
context.Load(coll);
context.ExecuteQuery();
 
 And then the collection will actually contain the WebTemplate objects you need.

Related posts

Latest posts

Leave a Comment

Leave a Reply

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