如何从列表模板创建新列表(客户端对象模型) [英] How do I create a new list from a list template (Client Object Model)

查看:39
本文介绍了如何从列表模板创建新列表(客户端对象模型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm creating the list based on custom list template. List is creating, but the custom list template is not applied for my list.

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

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

How can my code be modified to get the custom list applied?

推荐答案

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

Try this code given below. It should work for you. Let me know if you encounter any problem.

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 成员

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

TemplateFeatureId = Gets or sets a value that specifies the feature identifier of the feature that contains the list schema for the new list

这篇关于如何从列表模板创建新列表(客户端对象模型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆