Saturday, May 16, 2009

What are SharePoint Content Types?

One of the most powerful features of SharePoint version 3 is the introduction of content types. Not just are content types incredibly flexible, but they also allow a degree of control that far surpasses any other mechanism in SharePoint.

When I wrote issue 2 of Understanding SharePoint Journal, I assumed, perhaps wrongly so, that most people were familiar with the concept of SharePoint content types. I focused most of that issue on developing content types, but perhaps not enough time on explaining exactly what content types are.

So, I'm writing this relatively short overview. And I am saying relatively short, because any overview of content type must be vast, simply because of the span and importance of content types to any SharePoint solution.

SharePoint Content Types in five bullets:

1. SharePoint content types is a term used for describing a collection of metadata

For example, an invoice content type may contain a set of metadata such as buyer, date of sale, terms of delivery, order total, shipping cost, etc.

2. Content types support user interface customization

You can define the appearance of a content type, both while editing, creating, and displaying data based on the content type. For example, you may want to display or edit your invoices in a page resembling an actual invoice.

3. Content types support behavior through workflows and event receivers

Data derived from a content type can behave in a certain fashion or react to specific events. For example, an invoice may need approval from a manager, or you may want to prevent deletion of approved invoices altogether.

4. Content types can have specific user interface elements attached

Through the use of CustomAction elements, content types can have unique menu options attached to the user interface. For example, you may want to add a 'Pay now' menu option or button to an invoice, and only for an invoice.

5. SharePoint content types support inheritance of properties, appearance, and behavior

You can create content type hierarchies, for example by having a root accounting document content type that defines a set of metadata, user interface options, and behavioral settings, and have the invoice child content type inherit those settings and override or extend the definition to include the necessary modifications for an invoice.

If you think all of this sounds complex, don't worry. Content types are easy to use, and the complexity grows with your understanding.

How to Create Content Types

Creating content types is incredibly simple. You have access to the content types on the Site Settings page, accessible from the Site Actions menu. You can find the Site Content Type Gallery page by clicking the Site Content Types link in the Galleries section.

All content types inherit from an existing content type. The Site Content Type Gallery page gives you an overview of all available content types for your site and from which parent content type each content type inherits.

To create a new content type, click the Create button in the toolbar and type in a name and optional description for your new type. Then, select from which parent content type your new content type should inherit and choose or create a new display group or the type. Hit OK and you're done.

Once your new type is created, you can edit the settings for the content type, such as any new columns you want to add to your type, attach workflows to your content type, or change the name and description. You can also reach the content type configuration page from the Site Content Type Gallery, by clicking on the content type name in the list.

How to Use a Content Type

You need to attach your content type to a list or library in order to create items based on the content type. Generally, you can attach content types that inherit from the Document content type to a library and content types that inherit from the Item content type to most other lists.

To attach a content type to a list, go to the list settings of your chosen list and click the Advanced settings link on the Site Settings page. Click Yes in the section called "Allow management of content types?" and click OK. You will return to the Site Settings page and should now see a new section containing the content types. Click "Add from existing site content types", select your content type and click OK to add the content type.

You can now return to your list view and click the down-arrow on the New button to create a new item based on your content type. Note that any additional content type columns you added earlier will also be added to the list.

16.05

Some Questions about Content Types

Wait, this is too much, I prefer not to use content types. How can I avoid content types?

Your only choice to avoid using content types is not to use SharePoint. All data stored in SharePoint is stored using a content type. Even folders are content types. Therefore, you cannot simply choose to not use content types; you already are, if you are using SharePoint at all.

What do you mean? How can folders be content types?

The complete answer is beyond the scope of this short article, however, the fact that folders indeed are content types means you can also create new folder types and attach behavior and custom metadata to those folders. One example is to add a 'Zip Folder Contents' option to the folder menu.

Ok, you sold me, where can I learn more?

Mark Miller over at EndUserSharePoint.com has a beginner's guide to content types presentation available that will guide you through content types and show you some examples and best practices. EndUserSharePoint.com also has periodical workshop classes where you can learn even more about using content types. However, spaces in those classes are very limited, so I recommend you sign up for his newsletter to be notified whenever a new class is announced.

Of course, I may be a bit biased, but if you want to learn to develop more complex content types and harness all the power available, get issue 2 of Understanding SharePoint Journal, called Developing SharePoint Content Types. In that issue, I will teach you all the inner workings of SharePoint content types. Be prepared to get wet, though, because the content is targeted at people with some development experience.

.b

If you like this post or this blog, please visit the sponsors from SharePointAds.com and hear what they have to say:

5 comments:

Chris said...

B...I had a question about CTs and thought you might be able to answer it. Can you force your user to only be able to choose specific Parent content types from which to inherit? For instance, when I go to the ctypenew.aspx page can I make it such that when I select Document Content Types in the "Select parent content type from:" dropdown can I force the "Parent Content Type:" dropdown list to only show a specific few Document CTs rather than all of them?

Chris said...

B...I had a question about CTs and thought you might be able to answer it. Can you force your user to only be able to choose specific Parent content types from which to inherit? For instance, when I go to the ctypenew.aspx page can I make it such that when I select Document Content Types in the "Select parent content type from:" dropdown can I force the "Parent Content Type:" dropdown list to only show a specific few Document CTs rather than all of them?

Bjørn Furuknap said...

Chris:

You only option here is to make the aprent content type hidden. Doing so will remove the unwatned content types from the list, but this will apply to all users, including administrators.

This does not prevent you from inheriting from the content type using other means, however. For example, you may want to create a base content type that is hidden, and the create child document content types using CAML that are available for users.

There is no way to do this solely through the web interface, though.

Shoot me an email if this is not the answer you were looking for.

.b

Bjørn Furuknap said...

Chris:

Just one more note. You can, of course, create your own content type management, and that will allow you do to pretty much anything you like, but not with the default CT management, though.

.b

Chris said...

B...thanks for the reponse. It's not what I was hoping for but was what I expected. I want to force the users of my application to use ONLY those content types that I define for them. For instance, I want to have a "Company Document" CT inherited from Document but when they go to the ctypenew page I don't want them to see the base Document CT. I guess I could hide it but that would be a real pain in the future. I would want SC Administrators to be able to see it in order to create other CTs derived from it. I don't want to set it up so that every future CT needs to be implemented via CAML.