unable to find list templates programatically

Hi

All my List templates are available at:

http://xyz:1234/_catalogs/lt/Forms/AllItems.aspx

But programmatically I tried to find the list templates using the code below

SPListTemplate template123 = _objSPWeb.ListTemplates["abc"];

while debugging I tried to check the list templates using that code but it is not showing.

Please help

September 7th, 2015 9:04am

Hi Bharath,

You can  use below code to get collection of list template.

public static void GetListTemplateFromWeb(SPSite Site ){
          SPListTemplateCollection listTemplates = Site.GetCustomListTemplates(Site.OpenWeb());
            Guid myTemplateId =Guid.Empty;

            //loop throug all templates and find your template id
            foreach (SPListTemplate template in listTemplates)
            {
                Console.WriteLine("Template name",template.Name);
                if (template.Name.Equals("MyListTemplate"))
                {
                  //whatever you wish to do
                }
            }}

Let me know if this helps.

Please mark this as answer if this helps.

Thanks

Bhism

  • Marked as answer by Bharath Ch 3 hours 0 minutes ago
Free Windows Admin Tool Kit Click here and download it now
September 8th, 2015 12:29am

Hi,

Please use the following code to get the list templates from the List Template Gallery.

using (SPSite site = new SPSite("http://sp2013sps"))
{
    SPListTemplateCollection listtemplates = site.GetCustomListTemplates(site.RootWeb);
    SPListTemplate temp = listtemplates["abc"];                
}

Or

using (SPSite site = new SPSite("http://sp2013sps"))
{

    using (SPWeb web = site.RootWeb)
    {
        //open the list template gallery for this web
        SPList gallery = web.Lists["List Template Gallery"];
        foreach (SPListItem template in gallery.Items)
        {
            //find the timestamp doc lib
            if (template.Title.Equals("abc"))
            {
 
            }
        }
    }
}

Best Regards,

Dennis

September 8th, 2015 12:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics