I am trying to create a list based on a template I have saved.
Below code should get the list where the name is "ContactList" but I always get the error that a list by that name doesn't exist. (have tried with feature id also)
var listTemplate = site.ListTemplates.First(lt => lt.Name == "ContactList");
If I loop thorough all of the list templates I only get the "standard" templates back. If I press "Add app" i can see that my template list is there and I am able to add it.
clientContext.Load(site, s => s.ListTemplates);
foreach (var s in site.ListTemplates)
How can I add a list based on a existing template by code? Or can this even be done? I have only been able to add a standard "custom list"
Whole code:
var site = clientContext.Web;
clientContext.Load(site, s => s.ListTemplates);
clientContext.ExecuteQuery();
var listCreationInfo = new ListCreationInformation
{
Title = "ContactTest",
Description = "ContactTest",
};
var listTemplate = site.ListTemplates.First(lt => lt.Name == "ContactList");
listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;
listCreationInfo.TemplateType = listTemplate.ListTemplateTypeKind;
site.Lists.Add(listCreationInfo);
clientContext.ExecuteQuery();