SharePoint Declarative (CAML) vs Imperative (Object Model) Provisioning

There is a frequent debate around whether to use CAML or Object Model to provising Artifacts within a Site Collection or Site.

Declarative (CAML, XAML, XOML, etc. Markup-based Elements and Attributes)

Declarative CAML markup is used within Element Manifests which are part of a Feature that can be deployed via a Solution Package and activated at various scopes to provision artifacts.

Pro Con
Solution Generator (VSeWSS) and SPSource can be used to reverse engineer and create CAML CAML intellisense not well supported in IDE
Automatic handling of removal when a feature is deactivated (for Content Types and Site Columns)
Dependent on deployment via WSP and activation
Only way to provision CustomAction's No way to clean up provisioned Artifacts on deactivation
Can create site columns as Look Up fields and incorporate into Site Content Type or local list Content Type Can't create Look Up fields via CAML (SPFieldLookup) outside of the current web
  Requires a deactivate, retract, delete, add, deploy, activate to test in most scenarios (and then manual or script adding content...in C# or PoSH)

Imperative (Object Model-based Compiled Code)

Object Model code is used programatically within Feature Receivers which are part of a Feature that can be deployed via a Solution Package and activated at various scopes to provision artifacts.

Pro Con
Can debug through object model code Requires compilation of DLL and knowledge of programming C#/VB.NET
Most scenarios lines of code is shorter than CAML equivalent Can't easily change customization/configuration of components on the server
Can run code in Console Application or Powershell outside of scope of Feature Receiver for testing, reducing dependencies on testing Assemblies must be deployed to the GAC, which should in general be avoided when possible due to security issues
Full intellisense in IDE  
Better reuse by having Library Factories to provision Artifacts with parameters  

External References

Labels

caml caml Delete
programmatic programmatic Delete
declarative declarative Delete
api api Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Sep 01, 2009

    Anonymous says:

    Don't forget to discuss site definition provisioning via CAML and object model.

    Don't forget to discuss site definition provisioning via CAML and object model.

  2. Sep 02, 2009

    Alex Angas says:

    Can anyone from Microsoft comment on this? Presumably with the amount of docume...

    Can anyone from Microsoft comment on this?

    Presumably with the amount of documentation on MSDN put into the site definition and features structure this is the recommended path. But considering the pros and cons given (at the time of writing heavily favouring a programmatic approach) it doesn't seem to have a lot going for it.

    1. Sep 02, 2009

      Jeremy Thake says:

      So this debate around Site Features vs Site Templates vs Site Definitions has al...

      So this debate around Site Features vs Site Templates vs Site Definitions has already been covered before. I guess this is another extension but more directed at CAML vs Object Model if you are using Feature based approach.

  3. Sep 02, 2009

    Blake Blackshear says:

    I try to use CAML when I can.  I do find that once you start using the Obje...

    I try to use CAML when I can.  I do find that once you start using the Object Model, there is no turning back.  For example, using CAML, you can define columns, content types, and use those content types in a list definition.  However, when content types are created using the OM, you have no control over their ID, and can no longer use them in a list definition.  Sure you can create the list with the OM too, but if you have custom forms pages and fancy views it can make things challenging.

  4. Sep 02, 2009

    Corey Roth says:

    Ok, I confirmed that you actually can add lookup columns via CAML using the path...

    Ok, I confirmed that you actually can add lookup columns via CAML using the path to the list.  There are a few caveats but it does work.  Here is my post on it with more info.

    Also the main pro for me with CAML is that it does not require code compilation.  Also Content Types / Site Columns are cleaned up on feature deactivation.  I wish everything else was too though. :)

    1. Dec 10, 2009

      Brian Bedard says:

      What you like your end users yelling at you because the site owner deactivated y...

      What you like your end users yelling at you because the site owner deactivated your feature and all the data in the provisioned lists was deleted also?? I think not. I've written deactivation code to "clean up" a web and then wish I hadn't. After the site owner does this, I usually take away their privileges

  5. Jan 08, 2010

    Hynek Cihlar says:

    There's a quite new tool that combines the advantages of CAML and OM approach. M...

    There's a quite new tool that combines the advantages of CAML and OM approach. Mossquito lets you to create your site structure visually and with the push of one button it deploys it to a SharePoint site. No hassle with XML definitions or OM coding.


Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare