Thursday, 14 June 2012

How to create list programmatically using Custom List Template


         SPWeb web = (SPWeb)properties.Feature.Parent;
                string internalName = "Dashboard_Template.stp";
                SPListTemplate t = null;
                foreach (SPListTemplate template in web.Site.GetCustomListTemplates(web))
                {
                  if (template.InternalName.Equals(internalName))
                  {
                      t = template;
                      break;
                  }
                }
                if (t != null)
                {
                    web.Lists.Add("Dashboard", "Dashboard List", t);
                }
            }
            catch (Exception ex)
            {
              
            }


Method "spWeb.ListTemplates" - will only return out of the box templates. It will not return custom list templates.
if you want to create list by custom uploaded list template then use web.Site.GetCustomListTemplates(objweb) method .

No comments:

Post a Comment