简体   繁体   English

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

[英]SharePoint: How do I create a new list from a list template?

I've created a list template based on an Issue list and it is saved in the List Template Gallery. 我已经基于问题列表创建了一个列表模板,并将其保存在列表模板库中。 Now how do I create a new list based on this template? 现在如何基于此模板创建新列表?

I just encountered the same situation today. 我今天刚遇到同样的情况。
I saved a list as a template and i wanted to use that template in a new list. 我将列表另存为模板,并且希望在新列表中使用该模板。
On Sharepoint 2013, go to Site Contents > Add an App > 在Sharepoint 2013上,转到“ 网站内容”>“添加应用程序”>“
Scroll down and you will see a page numbering saying that you are on page 1 向下滚动,您将看到页面编号,表明您在第1页上
Click on the second page and all your saved templates will be there 单击第二页,所有保存的模板将在此处

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);

I'm surprised that Johan Leino's answer is marked as useful multiple times as it doesn't work in this particular case. 令我惊讶的是,约翰·莱诺(Johan Leino)的答案多次被标记为有用,因为在这种情况下不起作用。 If you create a template yourself, web.ListTemplates does not store it and you won't be able to create the list. 如果您自己创建模板,则web.ListTemplates不会存储该模板,因此您将无法创建列表。 It's only working for out-of-the-box templates. 它仅适用于现成的模板。
If you want to create a list based on your custom template you need to do it this way: 如果要基于自定义模板创建列表,则需要采用以下方式:

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 }

It probably just took a while for the timer job to fire. 定时器作业可能要花一些时间才能触发。

The template eventually showed up as an option under Lists > Create > Tracking section after a few minutes. 几分钟后,模板最终显示为“ Lists > Create > Tracking section下的一个选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM