Friday, June 12, 2009

Visual Studio Extensions: How to Change Base Type of Content Type

Recently I came across an interesting challenge. I needed to create some custom fields on my custom Page Layout for a client. I needed to add about 3 fields in addition to the fields in the existing page layouts (MetsKeywords, MetaDescription and a PageContent2 which were multi-line, multi-line and HTML fields respectively).

I went ahead and tried to create a custom content type in the VSEWSS and it popped open the Base Type dialog box. I wanted the Article Page to be my base type, but I didn't find it in the dropdown. I figured it would be easy to change later and so I picked Item as my base.

The first piece that was puzzling is that even though I picked a base as part of creating the content type, there was no reference to that base in the xml file. There is an attribute in the content type xml called BaseType which I figured I could set to the ctype ID of the actual base type I wanted (you can go to your SharePoint site, go to site settings, content types, and click on the content type you wish to inherit from - you will notice the ctype id in the URL. I copied and pasted it in the BaseType attribute and deployed and it still did not work.

After some digging around, I realized that the BaseType does not define the parent type. The parent type ID has to be the first part of the ID of the current content type. What I do now is copy the parent ID into the ID of the content type - and add 0D after that to specify the association.