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

时间:2022-01-06 02:59:31

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?

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

4 个解决方案

#1


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

#2


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页上单击第二页,所有已保存的模板将在那里

#3


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.

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

#4


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 }

#1


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

#2


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页上单击第二页,所有已保存的模板将在那里

#3


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.

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

#4


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 }