DotNetCurry Logo

Custom Content Types in SharePoint

Posted by: Sumit Maitra , on 12/13/2010, in Category SharePoint
Views: 98790
Abstract: Content Types in Windows SharePoint Services (WSS) or SharePoint Foundation enables users to define and group meta-information about SharePoint content. In this article, we will see the steps required to setup a custom content types in SharePoint and use it.

Content Types in Windows SharePoint Services (WSS) or SharePoint Foundation enables users to define and group meta-information about SharePoint content.

Typical use for Custom Content Types are in scenarios where a certain set of business specific data types need to be defined. For example if there is a business group that handles all policy making in a company they might want ‘New Policy Template’ and ‘Grandfather Policy Template’ to capture various policies in the company. Another example would be ‘Functional Specifications Template’ and ‘Technical Design Template’ for the engineering group. Such templates would mandate whenever a new document of the said type is created it should have a certain set of data. This set can be configured as a content type in SharePoint.

What metadata do Content Types save?

Simply put, Content Type is a set of field definitions. How are they different from standard Lists in SharePoint? Lists are specific to a location, content types are not. Content types in fact represent the blue print or schema definition that can be applied to a List or any other type of library for that matter. Content Types can also be scoped at site level such that they are available to an entire site hierarchy.

How to create Content Types in Sharepoint?

Content Types can be created in multiple ways

1. Through WSS/SharePoint Foundation User Interface
2. Through code using SP object model
3. Defining an xml based on a pre-defined schema and then deploying the xml as a SharePoint feature.

Each of these techniques deserves an article of its own. In this article, we’ll only cover the first technique.


Defining a Content Type using SharePoint Foundation User Interface

In the following example we will define a content type for a Functional Specification Document

Step 1: Log in a site collection administrator or Site Owner

Step 2: Navigate to Site Settings

Step 3: Under Galleries select ‘Site Content Types’ 

Site Content Types 

Step 4: In the Content Type Library select ‘Create’ 

Create Site Content Type 

Step 5: Define the Content Type 

Define Content Type 

a. Name: The name of the content type.
b. Description: Some help text describing what the content type is for.
c. Parent Content Type: Content Types can inherit from existing content types and they are grouped together by a Group Name
      i. Parent Content Type from: Select an existing group. Since we are defining a content type that will be used to   generate a document we use the ‘Document Content Type’ group
      ii. Parent Content Type: We want the content type to be applied when we are adding a new page to a page library in the site, so that each Functional Spec is published as a page.
d. Group: Select under which group our new content type should be categorized. Since it’s template for a Functional Specification Document we’ll categorize it under Document Content Types
e. Click Ok to complete basic content type definition 

Content Type Def 

Step 6: Defining Columns

a. By default the content type inherits from the Page content type and gets the Name and Title columns.
b. Now we have two options, either we select columns that already exist or define new columns. 

    i. Let’s select some existing columns 

       Content Type Columns

  • We select Author and Email columns from the existing set of columns 
  • While selecting the columns we get the option (Update all content types inheriting from this type?) to force our new columns down the entire content hierarchy. So if there are some other content types that inherit our content type we can force it down to those content types or just keep the changes for this content type.
  • Click OK to save changes 

    Content Type Info 
  • As seen above ‘Author’ and ‘E-mail’ are both set up as Optional columns. But we would rather have these as mandatory. So click on each column to update their settings 
  • We can edit the Site Level column name too. Remember these are site level columns so changes affect the site. Let’s change the 20th century ‘E-mail’ to a more contemporary ‘Email’. 

    New Site Column 


    ii. Add new columns: Let’s add new columns by using the Add from new site column link

1. Major Revision:
    a. Column Name: Major Revision
    b. Type: Choice
    c. Group: Custom Columns
    d. Additional Settings:
         i. Specify some descriptive text
         ii. Give choice values 1-10
         iii. Set default choice to 1

2. Minor Revision:
     a. Column Name: Minor Revision 
     b. Type: Choice
     c. Group: Custom Columns
     d. Additional Settings: 
          i. Specify some descriptive text
          ii. Give choice values 1-10

3. Approved By: 
    a. Column Name: Approved By
    b. Type: Person or Group
    c. Group: Custom Columns
    d. Additional Settings: 
        i. Description: Name of approver. Needs to be present in the SharePoint User List
        ii. Allow multiple Selections: Yes
       iii. Allow Selection of: People Only
       iv. Choose from: All Users
       v. Show Field: Name (with presence)

4. Table Of Contents 
     a. Column Name: Table Of Contents 
     b. Type: Full HTML content with formatting and constraints for publishing
     c. Group: Custom Columns

5. Problem Definition: Use same settings as 4b and 4c.

6. Functional Requirements: Use same settings as 4b and 4c

7. System Requirements: Use same settings as 4b and 4c

8. Open Issues: Use same settings as 4b and 4c

c. That’s it, we’ve defined a content type that roughly outlines what data we would like to capture as a part of our Functional Specification Document

Using a Content Type in SharePoint

Once we’ve defined the content type we are free to use it site wide. In our case we’ll create a new Page Library just to store functional specs. So navigate to existing ‘Libraries’ and click on ‘Create’.

Sharepoint Create Library

In the popup select ‘Library’ and ‘Document Library’. 

Sharepoint Document Library

 Give a Name and click on More Options. Select settings as shown below and click ‘Create’ 

CreateDocumentLibrary 

Now we’ve to tell SharePoint that for this document library use the newly define content type. To do this we need to apply following changes:

Step 1: Go to Site Settings and under Site Administration select Site Libraries and List to get to the list of available libraries. 

FunctionalSpecLibrary 

Step 2: Click on ‘Customize “Functional Specifications Library” as shown in the screenshot above, to navigate to following page 

Functional Spec Library Advanced 

Step 3: Click on Advanced Settings to enable content Management by selecting ‘Yes’ for Allow management of content types 

Allow Content Type Management 

Once we click okay we’ll see a new Content Pane is now visible in the List Information page 

Sharepoint Add From Existing Content Type 

Step 4: Click on ‘Add from existing content types’ link to select our newly created content type 

Select Content Type 

Click Ok to add the content types

Step 5: We don’t want users to use any other content type so we’ll ‘Change new button order and default content type’ 

Content Type Visible 

To do this we make the Document content type invisible.

That’s it, we are done.

Creating a new page with our custom content type


Step 1: Navigate to the page library and select the Documents Ribbon. Then select the New Document pull down menu, you’ll see the newly defined template as the only template to select from 

Sharepoint New Document 

Step 2: Select it and give a name to the new specification doc and click Create 

Sharepoint New Specification Doc 

Step 3: SharePoint Foundation will pop up a rich text editor. This editor comes up based on the ‘Layout’ defined. Currently our page library uses the ‘Base Page’ layout. Hence it does not know what fields to show here. How to create custom layouts is a separate topic and out of scope for this article. 

Sharepoint Rich Text Editor 
Then how do we see our fields that we added in the custom type? Cancel out of the Rich Text editor and click on the Page ribbon tab. 

Sharepoint Page Ribbon 

Step 4: From Edit Properties pull down menu, select View Properties. 

Functional Spec Content Properties 

Step 5: Now you can see all the columns we defined for our content type

Step 6: Expand the popup to fill screen and click on Edit Properties 

Edit Functional Spec Content Properties 

Step 7: Save changes and Check in. We are done.

Conclusion

We saw the steps required to setup a custom content types in SharePoint. This functionality is available in basic WSS 3.0 as well as SharePoint Foundation in other words it comes with your Windows Server license.

Custom Content Types gives you flexibility to define columns schemas independent of location.

This was a basic introduction. We can do a lot more with Content types and all the options that we did not use above.

What Next?

In subsequent articles I’ll be explaining how to make our Functional Specification ‘Page’ actually show the data that we entered through the content type. Then we don’t have to resort to ‘Edit Properties’ to add/update content values. This is achieved through another SharePoint feature – Layouts. We’ll also see how we can setup workflows for approval of our Functional Specification Document as well.

Update: Read the next article SharePoint – Creating Page Layouts for Custom Content Types

References

http://msdn.microsoft.com/en-us/library/ms472236(v=office.12).aspx

 

Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+
Further Reading - Articles You May Like!
Author
Sumit is a .NET consultant and has been working on Microsoft Technologies since his college days. He edits, he codes and he manages content when at work. C# is his first love, but he is often seen flirting with Java and Objective C. You can follow him on twitter at @sumitkm or email him at sumitkm [at] gmail


Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by Alex Cim on Tuesday, December 14, 2010 1:19 AM
Good. While creating column can i create a filtered list using Filtered Lookup section. Can you give an example of how to use the query string in it
Comment posted by LanceS on Tuesday, December 14, 2010 8:16 PM
Can we also add custom actions to these content types?
Comment posted by Sumit on Wednesday, December 15, 2010 9:50 AM
@Alex
Hello Alex, I am assuming you meant while creating column we can add validation through a formula string and you are looking for more info on that. I guess we could have an entire article just on how to setup the query string. One 'hack' I remember using was moving value from a system column to a user defined column. As I said that was a pure hack, but we can definitely do more useful stuff. I'll update the post once I have something more substantial in place.
If apologize if I got your question wrong, would request you to rephrase it in that case.
Comment posted by Sumit on Wednesday, December 15, 2010 10:03 AM
@LanceS
Since Content Types are typically used by associating them to some type of list (Page Lib, Doc Lib etc.) all custom actions that you can perform on Lists are applicable to Lists with associated content types. For example you could create an event handler on the ItemUpdated event and take action based on values set by users in the content type columns. Do let us know if this answers your question.
Comment posted by Alex Cim on Friday, December 17, 2010 1:54 AM
@Sumit -When you use the 'Create Column' page to add a column to the list you have a section called 'Filtered Lookup Configuration section' I want to understand how to use it with a query string configuration.
Comment posted by Bijay on Monday, May 9, 2011 5:11 AM
Below is a tutorial for creating a content type using SharePoint 2010 using visual studio 2010

http://www.fewlines4biju.com/2011/05/create-content-type-using-visual-studio.html

Thanks
Bijay
Comment posted by Stan Stevens on Monday, October 31, 2011 9:04 PM
In the section of Parent Content Type, i am not seeing Publishing Content Types as a choice. How can i add this? I am uning SP3 with Windows 2003 Server. Thanks.
Comment posted by raja on Thursday, November 3, 2011 4:57 AM
It is nice
Comment posted by gireesh on Wednesday, February 29, 2012 12:51 AM
Hi Sumit, it nice article. As u have explained. i need to do some thing like this.I have a Ms-word document template which contains employee name, employee Code etc in a tabular format. I have a employee list which contain employee information. So my question is: When i create a new document in my document library by making it content type can i Insert data from Employee List to ms-document template by providing some kind of screen to select employee Name.
Thanks & Regards
Gireesh
Comment posted by sasi Kumar Reddy on Monday, June 18, 2012 6:26 AM
I had placed all about content types with interview questions and answers.
http://sasikumarreddyv.blogspot.in/2012/06/content-types-in-sharepoint.html
Comment posted by sasi Kumar Reddy on Monday, June 18, 2012 6:38 AM
Good Post on Content types:

http://sasikumarreddyv.blogspot.in/2012/06/content-types-in-sharepoint.html