ContentTypeRef vs ContentTypeBinding

Interesting question came up as a result of a post of Chris O’Briens:

Interesting you raise ContentTypeBinding. I use this in other areas (e.g. associating content types with Pages libraries). Don’t think it had occurred to me that I could use it here also.

Which kinda makes me wonder why the schema provides two ways of doing the same thing, but that could lead to whole ‘nother discussion 😉

Well, I get interested by questions like that. As far as I can tell…:

  • ContentTypeBinding elements exist in the Elements of a feature. They’re so that a feature can bind a new content type to a list
  • ContentTypeRef elements exist in the schema of a List definition (List > MetaData > ContentTypes > ContentTypeRef)

So, you can use the ContentTypeRef to create a list with a content type, or you can use a ContentTypeBinding to add it later. And you should be able to do it in the same feature – you could use a ListInstance to create a list using your definition, and then bind your content type. And yes, it does rather look like all three bits could be in the one Feature.

  1. List to define the list
  2. ListInstance to create one in your site
  3. ContentTypeBinding to add your content type.

I wonder what happens if you try to create a list definition without a content type reference? Might try that for a giggle sometime.

Side note: the Property element on a File element in a publishing site with the key PublishingAssociatedContentType is for associating the file (a page layout) with a page content type, not for associating the page content type to the Pages library. You have to do that as well, using a ContentTypeBinding element. (Thanks Waldeck, that was driving me nuts!)

Advertisement
ContentTypeRef vs ContentTypeBinding

One thought on “ContentTypeRef vs ContentTypeBinding

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.