When creating content types and building out their hierarchies in your site, the content type id is an item that will always require a little extra care and attention. Rather than being a simple identifier like all other components in SharePoint (i.e., Feature Id, Solution Id, Field Id) the content type id contains hierarchy logic and requires a very specific format. To compound your troubles, there are two different methods for formulating the id. With this unique twist in mind, here are the 5 things your should know about content type ids.
1. Content Type Ids mean something
While the content type id uniquely identifies your content type within your site, it also contains the hierarchy logic of your type as well. The SharePoint SDK provides a good write up of the content type id format; and you should take the time to read it. Your content type id will consist of a parent id, followed by a ’00’, followed by your own guid or the parent id followed by a hex value other than ’00’.
While the content type id uniquely identifies your content type within your site, it also contains the hierarchy logic of your type as well. The SharePoint SDK provides a good write up of the content type id format; and you should take the time to read it. Your content type id will consist of a parent id, followed by a ’00’, followed by your own guid or the parent id followed by a hex value other than ’00’.
Parent Content Type ID + 00 + GuidParent Content Type ID + hex value
2. Don’t Panic!
If you forget to include the 00 between the parent id and your content type id, you will see some unusual things happen when you deploy the content type. Most of the time, these unusual things are disappearing content types particularly if you defined more than one content type in your xml document. Further, if you realize what you did and insert the 00 into your id and redeploy it without creating a new guid for your content type; your problem will not be fixed. Don’t Panic, add the missing element back in and create a new guid for your content type.
If you forget to include the 00 between the parent id and your content type id, you will see some unusual things happen when you deploy the content type. Most of the time, these unusual things are disappearing content types particularly if you defined more than one content type in your xml document. Further, if you realize what you did and insert the 00 into your id and redeploy it without creating a new guid for your content type; your problem will not be fixed. Don’t Panic, add the missing element back in and create a new guid for your content type.
3. Changing one part of the Id requires a new guid
Whether you have forgotten to include the 00 in your id, or you accidentally duplicated an existing content type id, or you are changing the parent of your content type; always, always create a new guid for your content type when you mess with the id. I can’t tell you why the id behaves this way or what the specific issues are; but from experience, when a part of the id changes, failure to create a new guid often results in a failed deployment of the content type or it results in no change to the original content type (in the case of changing a parent id).
Whether you have forgotten to include the 00 in your id, or you accidentally duplicated an existing content type id, or you are changing the parent of your content type; always, always create a new guid for your content type when you mess with the id. I can’t tell you why the id behaves this way or what the specific issues are; but from experience, when a part of the id changes, failure to create a new guid often results in a failed deployment of the content type or it results in no change to the original content type (in the case of changing a parent id).
4. Use the guid method
While the SDK provides you with two different methods for creating content type ids (guid or hex value). Your content type must be unique in the site. Since the hex method does not guarantee uniqueness as a guid does and it has fewer values, it suffers from a greater risk of being duplicated by another developer down the line who adds a content type to the site. The SDK recommends using the guid when you are inheriting from a CT created by someone else and then use hex after that point; however, this suffers from the same internal risk when a team developer comes along and inherits from an internal type and uses the same hex value as you.
While the SDK provides you with two different methods for creating content type ids (guid or hex value). Your content type must be unique in the site. Since the hex method does not guarantee uniqueness as a guid does and it has fewer values, it suffers from a greater risk of being duplicated by another developer down the line who adds a content type to the site. The SDK recommends using the guid when you are inheriting from a CT created by someone else and then use hex after that point; however, this suffers from the same internal risk when a team developer comes along and inherits from an internal type and uses the same hex value as you.
For example, in my previous post, I created a Character Sheet content type that inherits from Document. According to the SDK, I should use the guid method because I did not create the Document type. So, I create a content type id of 0x0101005497959230D94c409A4272826B9F1EDD. Now suppose I create a subtype of d20 Character Sheet to differentiate my role playing game sheets. I use the hex method to create a content type id of 0x0101005497959230D94c409A4272826B9F1EDD05. Let’s say, six months from now after I am off of the project and a coworker is now assigned and for whatever reason my id was not documented ("I’ll get to this later.") or the document was not read ("Who reads docs?") the new developer creates a content type for OGL Character Sheet and uses the same hex value. Now you have a problem which could have been avoided by using the guid method all the way through.
5. Be careful of the limitations
Having just said to use the guid method; there is a hard limit to the size of your id: 512 bytes or 1024 characters. Since each guid eats up 32 characters, a deep hierarchy can hit the limit very quickly. If you are developing a hierarchy that is pushing the 1024 character limit, you may need to use hex values and some very good documentation that other developers will read in order to achieve your hierarchy. OR, you can flatten our your hierarchy to work around the limitation.
Having just said to use the guid method; there is a hard limit to the size of your id: 512 bytes or 1024 characters. Since each guid eats up 32 characters, a deep hierarchy can hit the limit very quickly. If you are developing a hierarchy that is pushing the 1024 character limit, you may need to use hex values and some very good documentation that other developers will read in order to achieve your hierarchy. OR, you can flatten our your hierarchy to work around the limitation.