Below is my code
private void attachContentType(string siteURL, string path, string filename, ClientContext ctx, string folderName)
{
Web web = ctx.Web;
Microsoft.SharePoint.Client.File home = ctx.Web.GetFileByServerRelativeUrl(web.ServerRelativeUrl + "/" + folderName + filename);
ctx.Load(home);
ctx.ExecuteQuery();
home.ListItemAllFields["ContentTypeId"] = web.ContentTypes.GetByName("Page Layout").Id;
home.ListItemAllFields["PublishingAssociatedContentType"] = web.ContentTypes.GetByName("Content Type Name").Name;
home.ListItemAllFields.Update();
ctx.ExecuteQuery();
}
What I am trying to achieve is, set the type of the file to page layout, and set the associated content type to my custom content type.
This doesn't throw any exception, but when I edit the uploaded file it throws the below error
Failed to set value of the "Associated Content Type" column on the "Content Type ID" field type control
Content Type ID
to the page layout in the format of0x{CT_GUID}
. – moe May 23 '17 at 6:24