Tuesday, February 19, 2008

Always use CAPS in content type IDs

Content type ID in the typical form looks like 0x0100[GUID], where the part shown in bold is ID of a parent content type, 00 is a separator, and [GUID] is a GUID which makes content type ID unique. A good practice is to place GUID in CAPS only. You should always do it only this way! I'll show you why it is so important in a simple example.

Consider the following: you have a content type Test Item and you need to add a button Test Action to its display form, which links to some other page. To solve this problem, you will probably create a feature, which will deploy a content type and a custom action. Let's imagine that you will define your content type without dealing with this CAPS in GUID rule:

Name="Test Item"
Group="Test Content Types"
The custom action will be defined as:
Title="Test Action">
<UrlAction Url="#"/>
After deploying and activating this feature, you will see a strange issue - there will be no Test Action button in the display form of Test Item. To solve this issue, you should replace content type ID in both definitions (content type and custom action) with 0x0100EB06FD49D1764BC28CFE4F0971356D39. After redeploying the feature, this issue will be solved. That's why CAPS rule makes sense!