client object model add content type to list

血红的双手。 提交于 2019-12-10 11:23:07

问题


I have created an SP.List item "lst". I also:

lst.ContentTypesEnabled = true;
lst.Update();
clientContext.ExecuteQuery();

I have searched the AvailableContentTypes and found the one I want to add to lst. I then:

SP.ContentTypeCollection lstTypeCollection = lst.ContentTypes;

... 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 :-)


回答1:


Use ContentTypeCollection.AddExistingContentType method to add an existing content type to the list.

Example

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


来源:https://stackoverflow.com/questions/24310248/client-object-model-add-content-type-to-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!