What is the best way of provisioning ContentTypes, Columns and Metadata columns in SharePoint. Keeping in mind that we have two approaches of 1) SP object Model and CAML (declarative way). Which approach is the best especially if we have to add new columns later in the project ?

Any experience with this would be highly appreciated. I would also appreciate if you also have reference to a sample codeplex project.

P.S. we are provisioning these using the declarative way at the moment.


As always, the answer is: it depends.

If you're building a farm solution then I always suggest to go with code instead of CAML. You have more control and you can debug issues. If you're building a sandboxed solution you don't have a choice. You have to go with CAML since you can't use Microsoft.SharePoint.Taxonomy in the sandbox.

This blog post covers both options: How to provision SharePoint 2010 Managed Metadata columns


I personally prefer doing it in code as I can finely control the order and logic of when things get created. I can also use FeatureUpgrading to specifically add new things or change existing things if the Feature will be upgradable.

I've never tried to create Managed Metadata columns declaratively, but it's a sinch with OM code... here's an example walkthrough: http://blogs.msdn.com/b/sharepointdev/archive/2012/04/16/programmatically-create-a-managed-metadata-list-column-mohammed-faizan.aspx

  • 1
    Managed Metadata fields are tightly coupled to the MM Service Application they consume. If you inspect the Field elements (there will be two of them) that comprise a MM column(using SharePoint Manager), you will see GUIDs that refer to the term set they have been set up to consume. So in theory you could insert those Field elements into a Visual Studio solution and they will work, but ONLY if they are deployed to a web app that consumes the same MM Service Application. So I would try to avoid doing this declaratively, and go with the code-based approach instead. – Derek Gusoff Aug 2 '12 at 13:11

Here's an approach that defines the column declaratively, then hooks it up to the term set via a Feature receiver. This is probably as close as you're going to get to a purely declarative approach.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.