客户端对象模型将内容类型添加到列表 [英] client object model add content type to list
本文介绍了客户端对象模型将内容类型添加到列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个SP.List项"lst". 我也:
I have created an SP.List item "lst". I also:
lst.ContentTypesEnabled = true;
lst.Update();
clientContext.ExecuteQuery();
我搜索了AvailableContentTypes,并找到了我要添加到lst中的内容. 然后,我:
I have searched the AvailableContentTypes and found the one I want to add to lst. I then:
SP.ContentTypeCollection lstTypeCollection = lst.ContentTypes;
...现在我被卡住了.
lstTypeCollection.Add()
需要一个ContentTypeCreationInformation
对象
那时我正在黑暗中徘徊.
... now I'm stuck.
the lstTypeCollection.Add()
wants a ContentTypeCreationInformation
object
at that point I'm wandering in the dark.
你能说清楚吗?在此先感谢:-)
Can you shed light? Thanks in Advance :-)
推荐答案
Use ContentTypeCollection.AddExistingContentType method to add an existing content type to the list.
var list = context.Web.Lists.GetByTitle(listTitle);
list.ContentTypesEnabled = true;
var contentType = context.Site.RootWeb.ContentTypes.GetById("0x0120"); //get Folder content type
list.ContentTypes.AddExistingContentType(contentType);
context.ExecuteQuery();
这篇关于客户端对象模型将内容类型添加到列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文