list SharePoint:如何从列表模板创建新列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/945043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SharePoint: How do I create a new list from a list template?
提问by Even Mien
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?
我根据问题列表创建了一个列表模板,并将其保存在列表模板库中。现在如何基于此模板创建新列表?
采纳答案by Even Mien
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
几分钟后,模板最终显示为一个选项。
回答by Johan Leino
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);
回答by Faez abdulkarem
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 >
Scroll down and you will see a page numbering saying that you are on page 1
Click on the second page and all your saved templates will be there
我今天刚遇到同样的情况。
我将一个列表保存为模板,我想在新列表中使用该模板。
在 Sharepoint 2013 上,转到“站点内容”>“添加应用程序”>“
向下滚动”,您将看到一个页码,说明您在第1页上
单击第二页,您保存的所有模板都将在那里
回答by tsap
I'm surprised that Johan Leino's answer is marked as useful multiple times as it doesn't work in this particular case. If you create a template yourself, web.ListTemplates
does not store it and you won't be able to create the list. 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:
我很惊讶 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 }