Can you imagine a news website without any sort of control for the pictures being uploaded to the front page?
Content types (CT) are a big part of any well-planned content management system. In our enterprise we have a dedicated content team who is in control of the CTs for the CMS. They are extremely good at what they do and they really have a good grasp about the business, its processes, documents and metadata. Unfortunately, to deal with legacy systems is the issue and our legacy issue is to unify all the websites and its lists with its correct content types.
Early this week I had to find a way to setup and modify the versioning settings for the lists of our sites. As we can see, this can easily be done via Site Settings option. The issue here is that we have hundreds of sites, not to mention all the Team Sites, across all the enterprise. And possibly thousands of libraries. Meaning: It is impracticable to do this via UI. So, programmatically was the choice.
And honestly, this choice did not look so hard… at first at least.
The SPList object model exposes to us all the properties necessary do control these options enumerated in the page (as we will see in our code later) but make no mistake, the solution is not as trivial as one might think. The biggest problem is here: Enable Content approval.
Let’s do a short parenthesis here and reflect about this matter, from the business point of view.
And that’s a vital piece of functionality. Imagine a news website, like www.CNN.com or www.BBC.co.uk, possibly with hundreds of employees/contractors working on the website content. They write news stories, upload pictures etc. As an editor, would you give them any level of access they want? Of course not. In the ideal model, we must have a group of people responsible to approve the content being displayed to the public (i.e. using the Content Approver role). The last thing an editor wants to see is some crazy text flaming around everyone and displaying unacceptable behaviour (i.e. a text with racist remarks), or a picture that does not reflect the news report, or even worse, a picture that can potentially harm the viewers for being shown in the public.
To make short a long story: A content-based enterprise needs someone to be responsible for content approval.
Now, coming back to our technical venue.
Of course we want to enable content approval. So we go ahead and call:
SPList.EnableModeration = true
And out of the blue during some point of the execution an exception is thrown every time this line is called. That was a surprise for me.
So I went on to MSDN to read about the property and the object and…no clues or answer to be found. I went to see what happened with the other libraries using the same code. In the vast majority of the libraries where I ran that code, they let me update this property, but a few did not. so, what went wrong?
Then after some research and no clear answer, I decided to debug the SharePoint DLL via code reflection. I went to see on MSDN which of the SharePoint DLLs contains the SPList object and as indicated it is the Microsoft.SharePoint.DLL.
I’ve got the DLL and then compared the signature of my reflected copy against the copy installed in the GAC. Just to make sure we all were talking about the same “story”.
Note the member signature. There is nothing unusual here. It is a get / set, but let’s take a closed look at the SET method:
Interesting. “if the base template is a picture library then ERROR”.
Regardless of any test or comment. If we are dealing with a picture library, it seems to me that you can not enable content approval for it in SharePoint and immediately an exception is thrown.
IMO, I find this quite odd because in other instances, similar to this case, it is common place to expose another member to validate this test. For example, I would look for something like along the lines SPList.CanEnableContentApproval.
Anyway, moving on, problem found. I am not sure why content approval is not available for picture libraries. Indeed, if you go to the versioning settings for a picture library you won’t even see these options listed.
The solution : As of today, for me the way out of this is to use document libraries to handle the approval process for images. (if you have any other strategies for this matter, please let me know)
Now let’s take a look at the code to handle the full versioning control. Enjoy.
1 /// <summary>
2 /// Applies the versioning settings to the list.
3 /// </summary>
4 /// <param name="selectedList">The selected list.</param>
5 public void ApplyVersioningSettings(Microsoft.SharePoint.SPList selectedList)
6 {
7 // enable content approval for this list
8 // moderation is not supported for picture library types
9 if (selectedList.BaseTemplate != SPListTemplateType.PictureLibrary)
10 selectedList.EnableModeration = true;
11
12 // enable versioning for this list
13 selectedList.EnableVersioning = true;
14
15 // set security to only users who can approve and the actual content author
16 selectedList.DraftVersionVisibility = DraftVisibilityType.Approver;
17
18 //enable minor versions for this list
19 selectedList.EnableMinorVersions = true;
20
21 //set YES to forced checkin/checkout required
22 selectedList.ForceCheckout = true;
23 }
See you later
By Edge Pereira
Hi,
ReplyDeletefirst i need to know which tpye of site you are using for this example or any specifuc type of picture library as i am not able to see this option of "enabling content approval", i only see the versioning related option. i am using MOSS with SP2 and my site is publishing site. i have created a library of type "Picture Library".
Secondly the code u have mentioned, where it is should be placed? should we develop a feature and use this code in it?
Thanks
This comment has been removed by the author.
ReplyDeletePicture Libraries does not have content approval. Note that the article is comparing against a 'Document Library'.
ReplyDeleteThe code can be placed anywhere in your code when you wish to enable or disable the properties they talk about. You can, for example, create a console application to modify the properties of a specific list.
Thanks for the quick reply, i made this code as part of my feature and it is working fine. thanks again
ReplyDeleteI think you can enable approval for picture libraries; open the site in Sharepoint Designer, then right-click on the Photo Library and choose "properties". On the settings tab, put a check in the box for "Require content approval..." and then ok/apply.
ReplyDelete...not sure why this wasn't surfaced to the web interface, but, like I said, it was an option available to me (MOSS 2007 SP2) that works.