Csom creates content type and specifies guid

Source: Internet
Author: User

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";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.