gpt4 book ai didi

sharepoint - 如何从列表模板创建新列表(客户端对象模型)

转载 作者:行者123 更新时间:2023-12-04 18:49:01 24 4
gpt4 key购买 nike

我正在根据自定义列表模板创建列表。列表正在创建,但自定义列表模板不适用于我的列表。

ListTemplate template = null;
ListTemplateCollection ltc = context.Site.GetCustomListTemplates(context.Web);
context.Load(ltc);
context.ExecuteQuery();

foreach (ListTemplate t in ltc)
{
if (t.InternalName == "STPDiv.stp")
{
template = t;
break;
}
}

ListCreationInformation info = new ListCreationInformation();
info.Title = "TestCreation";
info.TemplateType = template.ListTemplateTypeKind;
info.TemplateFeatureId = template.FeatureId;
info.QuickLaunchOption = QuickLaunchOptions.DefaultValue;
site.Lists.Add(info);
context.ExecuteQuery();

如何修改我的代码以应用自定义列表?

最佳答案

试试下面给出的这个代码。它应该适合你。如果您遇到任何问题,请告诉我。

ClientContext context = new ClientContext("<Your Site URL>");
Web site = context.Web;
context.Load(site);
context.ExecuteQuery();

//Create a List.
ListCreationInformation listCreationInfo;
List list;

listCreationInfo = new ListCreationInformation();
listCreationInfo.Title = "<Your Title>";
listCreationInfo.Description = "<Your Description>";

var listTemplate =
site.ListTemplates.First(listTemp => listTemp.Name == "<Your Template Name>");
listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;

list = site.Lists.Add(listCreationInfo);
context.ExecuteQuery();

根据微软: ListCreationInformation members

TemplateFeatureId = 获取或设置一个值,该值指定包含新列表的列表架构的要素的要素标识符

关于sharepoint - 如何从列表模板创建新列表(客户端对象模型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9107570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com