0

I'm not able to access all the default list templates. I'm getting the error as invalid list template

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
namespace ClassLibrary1
{
    public class Class1
    {
        public static void Main(string[] args)
        {
            using (ClientContext context = new ClientContext("http://chnsharepoint:38940/listlibrary"))
            {


                    // The SharePoint web at the URL.
                    Web web = context.Web;
                    ListCreationInformation Info = new ListCreationInformation();
                    Info.Title = "117NoCodePublic";
                    Info.TemplateType = 117;
                    List list = web.Lists.Add(Info);
                    list.Update();
                    context.Load(web);
                    context.ExecuteQuery();


            }
        }
    }
}
1

Try below code,

// Get the list template by name
ListTemplate listTemplate = web.ListTemplates.GetByName("templateName");     
ctx.Load(listTemplate);
ctx.ExecuteQuery();     
ListCreationInformation creationInfo = new ListCreationInformation();
creationInfo.Title = "My List";
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();
1

Try it like this:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using Microsoft.SharePoint.Client;  
namespace ClassLibrary1   
    {  
       class Program   
        {  
            static void Main(string[] args)   
            {  
                //ClientContext - Get the context for the SharePoint Site    
                ClientContext clientContext = new ClientContext("http://chnsharepoint:38940/listlibrary");  
                //Get the SharePoint web    
                Web web = clientContext.Web;  
                ListTemplateCollection templateCollection = web.ListTemplates;  
                clientContext.Load(templateCollection);  
                //Execute the query to the server    
                clientContext.ExecuteQuery();  
                // Loop through all the list templates    
                foreach(ListTemplate template in templateCollection)   
                {  
                    Console.WriteLine("Template Name: " + template.Name);  
                }  
                    Console.ReadLine();  
                }  
            }  
        }  
  • Did this answer your question Vishal? If it did then please accept the answer and vote for it. Thanks – Kauser Oct 13 '16 at 19:26

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.