I’ve mentioned before that Content Types are much like classes in object oriented programming. While content types are not truly classes, there is a form of inheritance that occurs between a parent content type and its children. When you add a parent content type id in your content type id, your content type will inherit all of the site columns that are referenced up the hierarchy of content types. For example, if you create a content type that inherits from the Document type, your content type will inherit a reference to the Title site column. Using a hierarchy of content types in your site will help you better manage the use of site columns across more than one content type. You will be able to simplify your types by creating a generic type at the top that contains site columns that are common to all of your types, and move down from there to have content types with more specific sets of site columns.
In my previous posts, I have been building out a Role-Playing game site with a Character Sheet content type. Since then, I have also built out a Monster Sheet type. Although I have not yet defined any site columns I know that I have a few that will be common to both of these content types. In this article, I am going to add a base content type that will hold references to my common site columns. Then I will modify each of my existing content type’s ids so that the base type will be their parent types. Then I will package up and redploy the solution and validate that they are inheriting.
1. Create a base content type called RPG_Base
Creating the new content type is no different than when I created the Character Sheet. I create a new folder under the features folder to hold this type in its own feature. I add the feature.xml and contenttype.xml files to the folder and I populate them with the appropriate xml code to create the feature and content type.
Creating the new content type is no different than when I created the Character Sheet. I create a new folder under the features folder to hold this type in its own feature. I add the feature.xml and contenttype.xml files to the folder and I populate them with the appropriate xml code to create the feature and content type.
2. Modify the Content Type Id of my existing types
If you haven’t yet the five things you should know about content type ids, then take a moment to read it. When you change the Id of your existing types to inherit from the new base type, you must generate a new guid for your content type; otherwise you will have problems getting your hierarchy to work. Copy the content type id from your base type and paste it into the id attribute on your existing types; add a 00 to the end of the id; generate a guid and strip out the special characters.
3. If you are using an activator feature, then add your new features to it
Having your content type features hidden and automatically activated by a generic feature that has dependencies simplifies the deployment of multiple content type features. If you are doing this with your features, do not forget to add the feature ids of any new features to your activator feature. Otherwise, you may end up with hidden features that are not activated which will cause errors if they are parents in the hierarchy.
Having your content type features hidden and automatically activated by a generic feature that has dependencies simplifies the deployment of multiple content type features. If you are doing this with your features, do not forget to add the feature ids of any new features to your activator feature. Otherwise, you may end up with hidden features that are not activated which will cause errors if they are parents in the hierarchy.
4. Modify your manifest and ddf files to include any new feature and content type files
While feature and solution based development makes the deployment and management of SharePoint functionality easier, it adds quite a bit of up front work for the developer. You must remember to add your new content types, features, and files to a number of other files. Failure to do so means that things will not get copied, deployed, or activated when or where you expect. Whenever a content type fails to appear in the gallery, the first place I look is at the content type id, the second place is in the deployment files.
While feature and solution based development makes the deployment and management of SharePoint functionality easier, it adds quite a bit of up front work for the developer. You must remember to add your new content types, features, and files to a number of other files. Failure to do so means that things will not get copied, deployed, or activated when or where you expect. Whenever a content type fails to appear in the gallery, the first place I look is at the content type id, the second place is in the deployment files.
5. Make and upgrade your solution file
In my previous entry, I renamed the wsp file; in doing so, I retracted the first solution and re-added the solution to my farm. This time, I am using the same name for the wsp, so I can upgrade the solution rather than retract and redeploy. This gives me the benefit of versioning for my solution files, also an upgrade will automatically deploy the solution to the same sites that the existing solution is deployed to. This greatly simplifies the work that I have to do to deploy these new changes.
In my previous entry, I renamed the wsp file; in doing so, I retracted the first solution and re-added the solution to my farm. This time, I am using the same name for the wsp, so I can upgrade the solution rather than retract and redeploy. This gives me the benefit of versioning for my solution files, also an upgrade will automatically deploy the solution to the same sites that the existing solution is deployed to. This greatly simplifies the work that I have to do to deploy these new changes.
stsadm -o upgradesolution -name RPG_Content_Types.wsp -filename RPG_Content_Types.wsp -immediate
6. Validate the content types in the CT gallery
Go into the Site Settings of your site and click on the Content Types Gallery link. Locate your content types in the list and verify that they have the proper parent. In my case, the RPG_Base type is inheriting from Document, and the other two inherit from RPG_Base.
Go into the Site Settings of your site and click on the Content Types Gallery link. Locate your content types in the list and verify that they have the proper parent. In my case, the RPG_Base type is inheriting from Document, and the other two inherit from RPG_Base.