Share via


What are Content Type IDs?

So, a reader emailed me the other day, asking for more information on content type IDs: what they are, how to create your own, etc. Because he asked nicely, and because I like to keep both my readers happy, I decided to write up a quick overview of content type IDs.

The truth is, this is something I had hoped to get into the Beta 2 SDK, but the clock ran out. So his question gave me the perfect excuse to write the material up for the next refresh of the SDK. Consider this a preview then.

Because I’m planning on incorporating this material into the SDK, you’ll forgive me if I slip into my formal, developer documentation writing style.

<Authoritative SDK Voice>

Content type IDs uniquely identify the content type. Content type IDs are designed to be recursive. The content type ID encapsulates that content type’s “lineage”, or the line of parent content types from which the content type inherits. Each content type ID contains the ID of the parent content type, which in turn contains the ID of that content type’s parent, and so on, ultimately back to and including the System content type ID. By parsing the content type ID, you can determine which content types the content type inherits, and how two content types are related.

Windows SharePoint Services V3 uses this information to determine the relationship between content types, and for push down operations.

You can construct a valid content type ID using one of two conventions:

· Parent content type ID + two hexadecimal values

· Parent content type ID + “00” + hexadecimal GUID

There is one special case, that of the System content type, which has the content type ID of “0x”. The System content type is the sealed content type from which all other content types ultimately inherit.

For all other content types, you must use one of the above methods for constructing a valid content type ID.

Note that if you use the first method, the two hexadecimal values cannot be “00”.

A content type ID must be unique within a site collection.

Let’s examine each of these conventions in turn.

Windows SharePoint Services V3 uses the first method for generating content type IDs for the default content types that come included with the platform. For example, the content type ID of the Item content type, one of the most basic content types, is 0x01. This denotes that the Item content type is a direct child of System. The content type ID of the Document content type is 0x0101, and the Folder content type has a content type ID of 0x0120. By parsing these content type IDs, we can determine that both Document and Folder are direct children of Item, which in turn inherits directly from System:

In this way you can determine not only what content types a content type inherits from, but at which point two content types have common ancestors.

The figure below maps out the relationship of the four content types discussed above. In each, the unique portion of the content type ID is represented by blue text.

Windows SharePoint Services V3 employs the second content type ID generation convention when creating content type IDs for:

· Site content types you create based on other content types.

· List content types, which are copied to a list when you add a site content type to that list.

For example, if you have a content type with a content type ID of “0x010100D5C2F139-516B-419D-801A-C6C18942554D”, you would know that the content type was either:

· A site content type that is a direct child of the Document content type, or

· A list content type created when the Document site content type was added to a list.

In general, the first content type ID generation technique emphasizes brevity, in that it only takes two hexadecimal digits to denote a new content type. The second approach emphasizes uniqueness, as it includes a GUID to denote the new content type. Each approach is best in certain situations.

We recommend you use the GUID approach to identify any content types that are direct children of content types you did not create. In other words, use the GUID approach if the parent content type is:

· A default content type included in Windows SharePoint Services V3, such as Document.

· A content type developed by a third party.

That way, you are guaranteed that the content type ID is unique and will not be duplicated later by the developer of the parent content type.

Once you’ve uniquely identified a content type in this manner, however, you can use the first method to identify any children of that content type. In essence, the GUID used in your content type can act as a de facto namespace for your content type. Any children based on that content type can be identified by just two hexadecimal digits. Because the maximum length of a content type ID is finite, this approach maximizes the number of content type “generations” allowable.

Content type IDs have a maximum length of 512 bytes. Because two hexadecimal characters can fit in each byte, this gives each content type ID an effective maximum length of 1024 characters.

For example, suppose you wanted to create a new content type, myDocument, based on the default Windows SharePoint Services V3 content type Document. For the myDocument content type ID, you start with the Document content type ID, 0x0101, and append 00 and a GUID. This uniquely identifies the myDocument content type, guaranteeing Windows SharePoint Services won’t later add another default content type with the same content type ID (which would be possible, if you had only appended two hexadecimal digits). To generate content type IDs for any content types you derive from myDocument, however, you can simply append two hexadecimal digits to the myDocument content type ID. This keeps the length of the content type ID to a minimum, thereby maximizing the number of content type “generations’ allowable.

The figure below illustrates this scenario. Again, the unique portion of each content type ID is represented by blue text.

</Authoritative SDK Voice>

Now, the above information is probably most useful to developers working with the XML definition of content types. This way, if you’re looking at a content type ID in an XML file, or need to generate one for a content type definition file you’re writing, you’ll understand how to construct and parse them manually.

The SharePoint object model, on the other hand, includes methods to parser and compare content type IDs. Specifically, you can use the SPContentTypeID.Parent method to find the parent of a content type without having to parser the content type ID yourself. The SPContentTypeID object also contains several methods that enable you to compare content types by ID, and identify a common ancestor.

One last thing that might be of interest. If you want to take a look at actual content type IDs in WSS, here’s what you can do: navigate to the Content Type Gallery for a site. When you click on a content type, the URL to that content type contains a parameter, ctype, which is in fact the content type ID for that content type.

 

Written while listening to: The Replacements : Let It Be

Comments

  • Anonymous
    June 25, 2006
    PingBack from http://technote.thedeveloperside.com/?p=19
  • Anonymous
    July 10, 2006
    Today I'd like to talk about how to store and manage XML forms (InfoPath and otherwise) in WSS V3.
    In...
  • Anonymous
    August 30, 2006
    Planning Plan document management Chapter overview: Plan document management What is document management?
  • Anonymous
    September 14, 2006
    In case some of you missed it,  Andrew May has a good post on how to create content type ids for feature...
  • Anonymous
    October 03, 2007
    Document and Records Management Definition Document Management According to Wikipedia : &quot;A document
  • Anonymous
    February 27, 2008
    Body: Had some &quot;great fun&quot; with SharePoint over the last few days, basically when I copied
  • Anonymous
    July 27, 2008
    Document and Records Management Definition Document Management According to Wikipedia : &quot;A document
  • Anonymous
    September 29, 2008
    So continuing on from where we left off in Part 1 , you have a series of site columns to start with.