I have created new content type in CSOM, i need to set the newly created content type as default content type for the custom created sharepoint list. I am using below code.
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();
But the code gives error saying "System.NotSupportedException:'Specified method is not supported'" while querying on line no. 5
Can someone help?
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();
}