Upgrading ContentType Features

Upgrading contenttypes after they are deployed using a feature is quite a challenge. According to this MS article (http://msdn.microsoft.com/en-us/library/ms479975.aspx), it’s a big no-no to modify the Content Type definitions after deployment.

Under no circumstances should you update the content type definition file for a content type after you have installed and activated that content type. Windows SharePoint Services does not track changes made to the content type definition file. Therefore, you have no method for pushing down changes made to site content types to the child content types.

Off course, from a developers perspective, this is major drawback because it makes tasks that should be very trivial (like adding a column) virtually impossible.

After searching around the internet for a solution on how to update content types, I stumbled upon this post on Gary Lapointe’s STSADM blog.

Gary created an STSADM extenstion based on a post by Søren Nielsen that will update a content type by comparing all the fields in the content type in the lists where the content type is used.

The code works great, but is a bit limited as you have to run the stsadm command for each ContentType that you have deployed (of course, you could script the commands).

I’ve created an SPFeatureReceiver that uses Gary’s/Søren’s code to update all the ContentTypes that are deployed using the feature.

To update the ContentTypes, I just have to re-install the (updated) feature and re-activate it.

I will post the source as soon a I find some extra spare time.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>