SharePoint 2013 client object mode has a limit when creating content type. You cannot specify a guid for content type. It can only be generated randomly by the system. When using farm solution for deployment, you can specify the content type guid in XML or use the server-side object model to specify the guid.
After the release of SharePoint 2013 SP1, this problem was solved. In the new csom object model, you can specify the guid when creating the content type. Apply for a free development website on o365, and then write an app to test it.
Sp2013 SP1 csom SDK:
Http://www.microsoft.com/en-us/download/details.aspx? Id = 35585
After the SP version is upgraded to SP1, or on the o365 website, we can specify a unique guid for the content type. The Code is as follows:
Private string createcontenttype (clientcontext, Web web)
{
String contenttypeid = "0x010048017a06020108be8498bb193b944c84"; contenttypecollection contenttypecoll = clientcontext. Web. contenttypes;
Contenttypecreationinformation contenttypecreation = new contenttypecreationinformation ();
Contenttypecreation. Name = "contenttype name ";
Contenttypecreation. Description = "Custom content type created by csom .";
Contenttypecreation. Group = "Custom ";
Contenttypecreation. ID = contenttypeid;
// Add the new content type to the Collection
Contenttype Ct = contenttypecoll. Add (contenttypecreation );
Clientcontext. Load (CT );
Clientcontext. executequery ();
Return contenttypeid;
}
Note: When creating a content type, you cannot specify its parent content type in the code. For example, the following code cannot be executed normally.
Contenttypecreation. parentcontenttype = contenttypes. getbyid ("0x0100 ");
The correct method is to directly include the ID of its parent type in the specified guid, as shown below:
string contenttypeid = " 0x0100 48017a0602020.be8498bb193b944c84";