如何使用SharePoint 2016 CSOM& amp;列表模板的列添加到自定义列表中? C#? [英] How can the columns of the list template be added into the custom list using SharePoint 2016 CSOM & C#?
问题描述
我正在使用SharePoint 2016 CSOM& amp;创建一个列表模板的自定义列表C#。但是,在没有自定义列的情况下生成自定义列表。如何将列表模板的列添加到自定义列表中。有没有办法将新的
列添加到新的自定义列表?
$
              ListTemplateCollection templates = this.clientContext.Site.GetCustomListTemplates(this.clientContext.Web);
              this.clientContext.Load(templates);
              this.clientContext.ExecuteQuery();
              ////初始化列表或库创建信息
              var listCreationInfo = new ListCreationInformation
              {
                  Title = listName,
                  Description = listName
              };
              ListTemplate listTemplate = templates.First(listTemp => listTemp.Name ==" List1");
              listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;
              listCreationInfo.TemplateType = listTemplate.ListTemplateTypeKind;
              ////向网站添加新列表
              this.clientContext.Web.Lists.Add(listCreationInfo);
              this.clientContext.ExecuteQuery();
$
我们将非常感谢您的回复。
$
Hi,
I am creating a custom list from a list template using SharePoint 2016 CSOM & C#. However the custom list is getting generated without the custom columns. How can the columns of the list template be added into the custom list. Is there a way to add new
columns to the new custom list?
ListTemplateCollection templates = this.clientContext.Site.GetCustomListTemplates(this.clientContext.Web);
this.clientContext.Load(templates);
this.clientContext.ExecuteQuery();
//// Initialize list or library creation info
var listCreationInfo = new ListCreationInformation
{
Title = listName,
Description = listName
};
ListTemplate listTemplate = templates.First(listTemp => listTemp.Name == "List1");
listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;
listCreationInfo.TemplateType = listTemplate.ListTemplateTypeKind;
//// Add new list to site
this.clientContext.Web.Lists.Add(listCreationInfo);
this.clientContext.ExecuteQuery();
Your reply will be greatly appreciated.
推荐答案
I不太明白你想要什么。
I don't quite understand what do you want.
如果你想在你的列表模板中添加列,你上面的代码就不会添加列表模板了。
If you want to add columns to your list template, your above code is not adding a list template.
如果您想根据自定义模板向列表添加列,则如果您的模板包含列,则无需执行此操作。
If you want to add columns to a list based on your custom template, you needn't do that if your template has the columns.
这篇关于如何使用SharePoint 2016 CSOM& amp;列表模板的列添加到自定义列表中? C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!