I have already written a blog specifying how to create a List for SharePoint using Client Object Model. You can check that here.Though that code worked for most of the Lists, the List, Promoted Links, Report Library, and Asset Library, could not be created. They were constantly throwing the error, Invalid list template! As far as I was concerned, ListTemplates that were passed to the ListCreationInformation were correct. So why this error?? Here, I must also mention that I was trying to create these Lists on the Web template Team-Site.
The problem was I was only passing the baseTemplate to it. However, for these Lists, I needed to mention the GUID of the Feature, that contained the schema of the new List. Following is the modified code.
//use one of the templateName that suits your purpose string templateName = "Promoted Links";string templateName = "Report Library";string templateName = "Asset Library"; ClientContext ctx = new ClientContext(weburl); ctx.Credentials = new SharePointOnlineCredentials(userName, passWord); Web web = ctx.Web; // Get the list template by name ListTemplate listTemplate = web.ListTemplates.GetByName(templateName); ctx.Load(listTemplate); ctx.ExecuteQuery(); // Create a new object for ListCreationInformation class - used to specify the // properties of the new list ListCreationInformation creationInfo = new ListCreationInformation(); // Specify the title of your List creationInfo.Title = "My Custom List"; // Specify the list description, if any creationInfo.Description = "Description"; // Set a value that specifies the feature identifier of the feature // that contains the list schema for the new list. creationInfo.TemplateFeatureId = listTemplate.FeatureId; // Set a value that specifies the list server template of the new list creationInfo.TemplateType = listTemplate.ListTemplateTypeKind; web.Lists.Add(creationInfo); ctx.ExecuteQuery();
2 thoughts on “Create Promoted Links/My Report Library/Asset Library list in SharePoint 2013 using Client Object Model C#”
This is working for me with SharePoint Online….Thanks a looooot.