Upgrade ContentType using schema and code

Nov 14, 2008 at 7:52 AM
Hi,

First of all, thank you so much for this great documentation!

It says clearly in this documentation and on MSDN that it is not supported to upgrade the schema files for a custom ContentType. The supported way is to use code. Still I would like to upgrade the schema so that management of ContentTypes are easier. If I don't upgrade the schema I need to continuously upgrade the FeatureReciever for the ContentType to hold the code to upgrade it self to the latest version. After a couple of iterations, probably all the settings of the ContentType is now declared within the FeatureReciever and the point of have the schema seems to be lost. If I know that most settings of the ContentType will end up in the FeatureReciever I could as well start with a new empty ContentType inheriting from Document or Item and add all settings from the Receiver.

Instead I would like to have one single common Receiver for all my ContentTypes that on activation looks at the Schema and updates itself and any children if there are any modifications. With this approach I can still use the benefit of Schemas and have a simple way of managing ContentTypes. The important point is that when I do implement this, it actually works fine. So the question is, will this be supported or have I missed something important?

BR

Magnus Danielson
www.dunite.se
Developer
Nov 17, 2008 at 5:54 PM
Magnus,
Whether this is something that can be supported is really something that SharePoint product team has to decide. We've gone back and forth on this topic with the product team and our advisors. The product team insists that there may be unexpected results when overwriting the content type xml files on the web front ends. Now if the solution you mentioned works for you without any issues, then you should continue you to use it.

I do have a couple of question though. You mentioned having a single receiver for all your content types, can you elaborate on what that means? And when you say update itself, do you mean it updates the contenttype xml file? or the content type schema through the OM?
Nov 19, 2008 at 11:39 AM

Hi Charles,

Thanks for your reply. I am sorry if I was a bit unclear on the receiver, I will try to explain below.

1. Create a ContentType feature and deploy it with a solution.
2. Activate the ContentType on several SiteCollections.
3. Update the elements.xml files for the ContentType and rebuild the solution. ( I am using WSP-builder )
4. Retract, Delete, Install and Deploy the new version of the solution.
5. Reactivate the ContentType on all relevant SiteCollections.
6. The ContentType has a feature receiver for the activation event which calls my generic method UpgradeContentType().
7. UpgradeContentType opens the specific elements file for the current ContentType and updates all settings according to the new elements.xml through the OM.
8. UpgradeContentType calls the Update(true) method to update all children inheriting from this ContentType.

While typing a realized that my method does not necessarily have to get the updates from elements.xml, I could as well include another xml file in my feature called Upgrade.xml which follows the ContentType schema. I guess that would make my solution supported since I don't have to touch the original elements.xml. And on activation my method UpgradeContentType iterates through Upgrade.xml file to update the ContentType through the OM.

 BR

Magnus Danielson

www.dunite.se