5

I am trying to create custom list using a custom list template in csom. My lst get created but it doesn't contain the schema of the list template. It looks like a generic list.

Please let me know how can I create custom list using my custom template in CSOM?

ListCreationInformation lci; 
List listInstance;

lci = new ListCreationInformation();
lci.Title = listName;
lci.Description = listDescription;

ListTemplate lt = collection.First(z => z.Name == listTemplate);
lci.TemplateFeatureId = lt.FeatureId;
lci.TemplateType = lt.ListTemplateTypeKind;                        
listInstance = web.Lists.Add(lci);
context.Load(web.Lists);
context.ExecuteQuery();
  • Is below answer helps you? – Hardik May 30 '16 at 9:31
2

Please try below updated code.

using (var context = new ClientContext(url))
{
     //context.Credentials = credentials;
     var site = context.Web;
     context.Load(site,s => s.ListTemplates );
     context.ExecuteQuery();

     var listCreationInfo = new ListCreationInformation
     {
           Title = "<Your Title>",
           Description = "<Your Description>"
     };

     var listTemplate = site.ListTemplates.First(lt => lt.Name == "<Your Template Name>");
     listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;
     listCreationInfo.TemplateType = listTemplate.ListTemplateTypeKind;

     site.Lists.Add(listCreationInfo);
     context.ExecuteQuery();
}

Please add namespace System.Linq; if you haven't added it to your code.

  • 1
    Could you add some info about the code and not just an answer? – iOnline247 May 30 '16 at 14:04
  • @Nehal, is it working for you? – Hardik May 31 '16 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.