Enabling Content Approval on a List using CAML

Posted Thursday, October 8, 2009 5:16 PM by CoreyRoth

I’ve always liked the power of CAML because it allows me to create so much in SharePoint without ever having to write a line of code.  However, there really isn’t enough examples out there, so I like writing posts like these that focus on doing something very specific with a list.  @SPKyle would say just write some code to do that, but that’s not my style, so I did some digging through the SDK and some experimentation and I figured out how to do it.  Of course there isn’t an attribute called EnableContentApproval.  So, the first thing we have to figure out is what CAML calls content approval.  It turns out CAML refers to this as moderation.  We’ll add this to the SharePoint UI to API translation guide.  Looking at the List element, I find two attributes ModeratedList and ModeratedType.  The description of the both is quite similar, so I decide to try them out one at a time.  I find that setting ModeratedList works but setting ModeratedType does nothing.  No idea why there is two attributes.  Maybe one is deprecated.  Here is what a List element line would like in your schema.xml.

<List xmlns="http://schemas.microsoft.com/sharepoint/" BaseType="0" DisableAttachments="True" EnableContentTypes="True" Name="MyList" OrderedList="False" QuickLaunchUrl="True" Title="My List" Type="10001" VersioningEnabled="False" Url="Lists/MyList" Id="ed65344b-0399-4c34-8265-de0c2d193165" ModeratedList="TRUE">

I then go take a look at the list versioning settings of my newly created list, and everything looks good.  Note, if you want to turn on versioning, you can use the VersioningEnabled attribute that you see above.

ContentApproval

Again, I set the ModeratedList attribute in the List element of the Schema.xml.  Before I set it on the schema.xml file, I noticed that the ListTemplate element that you use in your elements.xml file had an attribute EnableModeration.  The SDK states this can be used to turn on moderation as well.  However, when using it I find that it does not work.  If I set it to true or false it does not work and does not seem to override I set in the schema.xml file.  Anyhow, if you ever need to turn on content approval and don’t feel like writing code, I hope this helps.

Filed under: , ,

Comments

No Comments

Leave a Comment

(required)
(required)
(optional)
(required)