Stumbling Through: SharePoint 2007 (Content Types - Part I)
While I do get to play a lot with WPF in my spare time, I still have to do some real work from time to time. That real work, for the time being anyway, involves using SharePoint 2007 and K2 Blackpearl to create a system for managing the assets of our company. I am completely new to both of these products, so there is going to be a lot of stumbling and bumbling here; please bear with me. I'm going to skip some of the business requirements stuff for the purposes of this blog and skip straight to the heart of the matter: We need to track many different kinds of company assets, each asset having their own unique attributes in addition to a number of attributes common among all assets. Sounds like something I read in a textbook in college to define the concept of object oriented programming... so how can I use that to my advantage given my technology choices? Lucky for me, my wife is currently becoming a SharePoint 2007 expert herself while doing Q/A work for another company, and when I told her my dilemma, her advice to me was simply: 'Content Types'. Very well then, content types it is, but what are they, exactly? Rather than a long-winded and confusing attempt at describing what they are, I am just going to jump into an example that uses them to the best of my crude abilities. I am going to assume that you have SharePoint 2007 installed, and that you have yourself a nice empty site to play with as an administrator. Now there are a bazillion different ways to install and configure SharePoint, so your screens may not look identical but hopefully the functionality will end up being the same.
Our first order of business will be to define our content types as related to this site. For the sake of this demo, lets say that I need to track Laptops, Monitors and Hard Drives as company assets. Each of these items will have a manufacturer, model and serial number. Monitors will additionally track 'Screen size', while hard drives will track 'Capacity'. Laptops will track a number of different things, we want to leave that open for expansion. To start defining content types, click your 'Site Actions' dropdown and select 'Site Settings':
Of the dazzling array of options we have at our disposal here, we want to select 'Site content types', which is the second option under the 'Galleries' section:
While your screenshot will likely differ than mine, what should be displayed is a list of content types already defined for the site by default:
Click the 'Create' button to bring up the 'New Site Content Type' screen. I will walk through each of the options presented here:
The first attribute, Name, is how this content type will be referred to from here on out. Description simply helps identify the purpose of the content type. 'Parent Content Type' is required, as all content types must derive from something. I've found that the 'Item' content type is the most basic. The first dropdown filters the items that appear in the second dropdown, making it easier to locate specific content types. Finally, in the 'Group' section, we are specifying that we want this content type to be added to a brand new group. This is the group that we will be adding all of our asset-related content types, and it will appear in the 'Parent Content Type' dropdown to help us find asset content types later. Click 'Ok' to save this new content type, and we are brought to a page that lets us further define our content type:
What we are specifically interested in here is the 'Columns' section, in which we see 'Title' as the only defined column. 'Title' was inherited by our 'Item' parent content type. Columns define the data that can be attributed to our content type, which if I were to go back to thinking 'object orientated-ly', means that the content type is our 'Class' and each column is a 'Property' of the class. So we will use the 'Add from new site column' action to create and associate our base asset columns that we defined previously - namely: Manufacturer, Model and Serial Number. For simplicity sake, we will make them all free-form text columns, though later I will hopefully show you how to make them into dropdowns from pre-populated lists or other fancy options. Click the 'Add form new site column' option, I will explain each item in the following screen:
The 'Name' is simply the name of the column as it will appear in any consuming content type. The 'Type' gives us a number of options that will affect the behavior of the column when it is being edited. There is a lot of power here, but we'll keep it simple and select 'Singe line of Text' for a free-form text field. The next section, group, will group the column into 'Clarity Asset Columns', to make it easier to find later. I have accepted the defaults for all of the other options. Click 'Ok' to create the column and associate it with the Asset content type. One thing to note here is that even though we created the column through the content type details screen, the column is not specific to that content type... it is created publicly and can be used in other content types. One unusual caveat is that in order to make this column required, we have to go back in and edit it to set that property. For some reason that option is disabled in the column creation screen. Let's do this by returning to our 'Site Settings' menu and clicking 'Site columns':
Note our 'Clarity Asset Columns' grouping appears, with the manufacturer column underneath. Click the Manufacturer column:
We see a similar screen to the column creation screen, though now we can specify that the column is required by selecting 'Yes' to 'require that this column contain information':
Click 'Ok' to save the changes, and return to our site content type and add the remaining columns: Model and Serial Number in the same fashion as the Manufacturer column so that your content type looks like this:
Weird that the columns still say 'Optional' when I thought I made them required? It looks like that is an option that can override the default, so it is specific to this content type's implementation of the column. To make them required for this content type, we'll have to click the columns individually from the content type screen and make them required:
Do that for each column, and your content type should look like this:
So we have defined our base asset content type, next up is creating our Laptop, Monitor and Hard Drive content types that derive from it. After that, we need to create a list that implements these content types so we can see them in action.