我已经在CSOM中创建了新的内容类型,我需要将新创建的内容类型设置为自定义创建的共享点列表的默认内容类型。我正在使用以下代码。
List aeList = ctx.Web.Lists.GetByTitle("Project Definition");
var currentCtOrder = aeList.ContentTypes;
ctx.Load(currentCtOrder, coll => coll.Include(
ct => ct.Name,
ct => ct.Id));
ctx.ExecuteQuery();
IList<ContentTypeId> reverseOrder = (from ct in currentCtOrder where ct.Name.Equals("Project Definition", StringComparison.OrdinalIgnoreCase) select ct.Id).ToList();
aeList.RootFolder.UniqueContentTypeOrder = reverseOrder;
aeList.RootFolder.Update();
aeList.Update();
ctx.ExecuteQuery();
但是代码在行号查询时给出错误信息,提示“ System.NotSupportedException:'不支持指定的方法'”。 5
有人可以帮忙吗?
答案 0 :(得分:1)
static void Main(string[] args)
{
ClientContext ctx = new ClientContext("http://sp/sites/jerry");
List list = ctx.Web.Lists.GetByTitle("Documents");
ChangeContentTypeOrder(ctx, list);
}
private static void ChangeContentTypeOrder(ClientContext ctx, List list)
{
ContentTypeCollection currentCtOrder = list.ContentTypes;
ctx.Load(currentCtOrder);
ctx.ExecuteQuery();
IList<ContentTypeId> reverceOrder = new List<ContentTypeId>();
foreach (ContentType ct in currentCtOrder)
{
if (ct.Name.Equals("testct"))
{
reverceOrder.Add(ct.Id);
}
}
list.RootFolder.UniqueContentTypeOrder = reverceOrder;
list.RootFolder.Update();
list.Update();
ctx.ExecuteQuery();
}