Provisioning in SharePoint has always been not the simplest part, especially if it concerns the Content Type provision.
It is known that in SharePoint 2010, you can declare content types in a feature or you can create them programmatically. Programmatically created content types are more flexible and provide more granular control over how and when updates to the content type are made during upgrades. In contrast, you cannot change the declarative definition of a content type that was created by using Collaborative Application Markup Language (CAML) after the content type is activated—instead, you must update the content type programmatically.
Given the Pros and Cons, it is up to you to decide which way is better suits your needs.
How to create a field based on the specified schema
There is one method that allows to create a field based on the specified schema, see AddFieldAsXml method for details . It means that you could declare a field once (CAML), but to provision it either via feature activation or programmatically. As for me, I find this technique very useful for curtain cases. But what about content types?
For content type there is no such capability that allows to create a content type based on the specified schema. And the goal of this post is to demonstrate how it could be achieved.
How to create a content type based on the specified schema
Listing 1. AddContentTypeAsXml method implementation for creating a content type based on the specified schema
Listing 2. AddContentTypeAsXml method implementation for creating a content type based on the specified schema via Managed Client Object Model
The following list summarizes the limitations for Client OM approach:
- Not the all content type attributes could be specified via Client OM
- In particular it is not supported to specify Content Type Id, only parent Content Type could be specified