All about Microsoft Office SharePoint Server Content Type – Part 2

In the part 1 of the article we covered

  • What is a content type
  • How content types work In this part 2 of the article I will cover the following
  • Extending content types
  • Attaching workflows to a content type
  • Attaching event handlers to a content type
  •  

    Extending Content Types :

    You can create site content types based on other site content types. To do this, the site on which you are creating your new content type must be in scope for the site content type from which you are deriving the new content type.

    In this way you can create a general site content type, which contains attributes common to several types of content, and then derive more specific site content types from it. This is exactly what Windows SharePoint Services does in its own built-in content type hierarchy. All content types ultimately derive from the System content type.

     

    Lets take the following hierarchy as an example. A parent site has a base content type called DocumentX. In the same site 2 other content types Spec and Memo inherits from DocumentX content type.

    A content type in a sub site ProductXSpec inherits from Spec content type. A list in that site uses ProductXSpec from the sub site and Memo from the parent site.

     

    image

     

    First I created a content type by name DocumentX from List Content Type group item as the base. (Refer to Part 1 of this article to find out more about creating a new content type) Then I created Spec and Memo content types choosing Custom Content Type group and DocumentX as the parent from the dropdown.

    image

     

    In the child site I created a new content type ProductXSpec that inherits from Spec content type.

    image

    then I created a list called ProductSpec which has content types enabled. In this list I associated the content type ProductXSpec and Memo.

    image

    Now I can enter content relating to ProductXSpec and Memo. The list content types ProductXSpec and Memo inherits from the parent but allows you to customize and the scope is limited to this list. I can now add a new column that becomes part of both ProductXSpec and Memo as well. Make sure that you choose “Add to all content types”

    The scope of this column is within this list content type and does not affect the site content type from which the list content type derives from.

    image

     

    Attaching workflows to a content type:

    The availability of a workflow within a site varies, depending on where it is added:

    • If you add a workflow directly to a list or library, it is available only for items in that list or library.
    • If you add a workflow to a list content type (an instance of a site content type that was added to a specific list or library), it is available only for items of that content type in the specific list or library with which that content type is associated.
    • If you add a workflow to a site content type, that workflow is available for any items of that content type in every list and library to which an instance of that site content type was added. If you want a workflow to be widely available across lists or libraries in a site collection for items of a specific content type, the most efficient way to achieve this result is by adding that workflow directly to a site content type.

    You can add a workflow to a content type and ensure that all content types inheriting from this base content type will also get the workflow attached.

    • Click Add a workflow and choose from the available default workflows out of the box or any custom workflow that is available in that site collection.
    • To ensure that all inheriting content types get this workflow select “Add this workflow to all content types that inherit from this content type? “

    image

    image

     

     

    Attaching event handler to a content type:

    You can attach event handler to a content type. I created a list in the ProjectXYZ subsite using a content type called ‘Spec’ created earlier.

    Then I created a EventHandler using the simple code displayed below.

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
     
    namespace ProductSpec.EventHandlers
    {
        class HandleDelete : SPItemEventReceiver
        {
     
     
            public override void ItemDeleting(SPItemEventProperties properties)
            {
                    properties.Cancel = true;
                    properties.ErrorMessage = "This is a readonly item 
    
    therefore you cannot delete it.";
     
            }
        }
    }

     

    I registered the event handler to the content type ‘Spec’ using the EventHandlerExplorer tool from U2U.

    image

     

    Once associated. I created a new list based on the ‘Spec’  content type. I added an entry into the list. When I try to delete I get this nice little message that I have added in the ‘ItemDeleting’ event.

    image

    * Note : To be continued in Part 3

    Useful Links:

    Part – 1 , Part – 2 , Part – 3 , Part – 4

    Advertisements

    3 Responses

    1. […] All about Microsoft Office SharePoint Server Content Type – Part 2 […]

    2. […] All about Microsoft Office SharePoint Server Content Type – Part 2 […]

    3. […] All about Microsoft Office SharePoint Server Content Type – Part 2 […]

    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 )

    Twitter picture

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

    Facebook photo

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

    Google+ photo

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

    Connecting to %s

    %d bloggers like this: