Ana*_*han 5 sharepoint sharepoint-2010
我正在基于自定义列表模板创建列表.列表正在创建,但自定义列表模板不适用于我的列表.
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();
Run Code Online (Sandbox Code Playgroud)
如何修改我的代码以应用自定义列表?
小智 6
试试下面给出的代码.它应该适合你.如果您遇到任何问题,请告诉我.
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();
Run Code Online (Sandbox Code Playgroud)
根据Microsoft: ListCreationInformation成员
TemplateFeatureId =获取或设置一个值,该值指定包含新列表的列表架构的功能的功能标识符
| 归档时间: |
|
| 查看次数: |
7224 次 |
| 最近记录: |