SharePoint:如何从列表模板创建新列表?

SharePoint:如何从列表模板创建新列表?,sharepoint,list,moss,list-template,Sharepoint,List,Moss,List Template,我根据问题列表创建了一个列表模板,它保存在列表模板库中。现在,如何基于此模板创建新列表?计时器作业启动可能需要一段时间 string internalName = "MyListTemplateName"; SPListTemplate t = null; foreach (SPListTemplate template in web.ListTemplates) { if (template.InternalName.Equals(internalName)

我根据问题列表创建了一个列表模板,它保存在列表模板库中。现在,如何基于此模板创建新列表?

计时器作业启动可能需要一段时间

string internalName = "MyListTemplateName";
SPListTemplate t = null;
    foreach (SPListTemplate template in web.ListTemplates)
     {
       if (template.InternalName.Equals(internalName)
       {
          t = template;
          break;
       }
    }    
        web.Lists.Add("nameoflist", "description", t);

几分钟后,模板最终显示为
列表>创建>跟踪部分下的一个选项。

我很惊讶Johan Leino的答案多次被标记为有用,因为它在这种特殊情况下不起作用。如果您自己创建模板,
web.ListTemplates
不会存储它,您将无法创建列表。它只适用于开箱即用的模板。
如果您想基于自定义模板创建列表,您需要这样做:

SPListTemplateCollection listTemplates = web.Site.GetCustomListTemplates(web);
SPListTemplate listTemplate = listTemplates["MyCustomTemplate"];
Guid listId = web.Lists.Add("My New List Name", "My Description", listTemplate);
if (listId != null) { //all good }

我今天遇到了同样的情况。
我将列表保存为模板,并希望在新列表中使用该模板。
在Sharepoint 2013上,转到网站内容>添加应用>
向下滚动,您将看到一个页面编号,表明您在第1页
单击第二页,所有保存的模板都将显示在那里