Click here to Skip to main content
11,926,933 members (49,465 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked

SharePoint Workflows for Folder Content Type

, 3 Feb 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
This article demonstrates how to start a Workflow from a custom Folder Content Type.


Applies to:

  • Microsoft® .NET Framework 3.0
  • Microsoft® Windows Workflow Foundation - WF
  • Microsoft® Windows SharePoint Services 3.0 - WSS
  • Microsoft® SharePoint Portal Server 2007 - MOSS

Short Overview:

A few months ago, I had to implement a MOSS 2007 (SharePoint) feature to start Workflows from a Folder Content Type. The problem was, you cannot attach SP Workflows to a Content Type that was derived from Folder. My solution for this problem was to implement an Event Handler feature which calls the SP Workflow when a folder item was added to my Custom List.


  • The Problem
  • Creating a new Document Library
  • Enabling the management of custom Content Types
  • Defining a new Content Type
  • Implementing the Event Handler feature
  • Implementing the Workflow

The Problem

In a few words, there is no option to manually start a Workflow from a Folder item.



Creating a new Document Library

To create a new Document Library, go under "All Site Content" and select "Document Library".

Defining a new Content Type

To create a new Content Type, go to "Site Settings"; under "Galleries", select "Site content types". In this page, click "Create" and fill the required values like in the following image:


Enabling the management of custom Content Types

In order to use custom Content Types in the newly created Document Library, you need to enable this option. To set the option, you need to navigate to "Document Library Settings", and under the "General Settings" group, select "Advanced Settings". See the image below:


Also, you need to add the new "FolderContentType" to the "Folders" document library. Under the "Content Types" group, select "Add from existing site content types" and search for "FolderContentType" having "Custom Content Types" selected in the dropdown. Click "Add" and then "OK". In the "Folders" document library, expand the "New" menu and see the "FolderContentType" menu item, for creating a new FolderContentType item.

Implementing the Event Handler feature

The Event Handler which will be called when a new "FolderContentType" is created in the "Folders" document library is based on the SPItemEventReceiver class from the Microsoft.SharePoint namespace. We need to override the ItemAdded method as follows:

public class FolderContentTypeWorkflowStarter : SPItemEventReceiver
    public override void ItemAdded(SPItemEventProperties properties)
        SPWeb web = properties.OpenWeb();

        SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[properties.ListId];

        if (properties.ListItem.ContentType.Name == "FolderContentType" &&
            properties.ListItem.Folder.ParentFolder.ToString() == 
            SPSite site = web.Site;
            SPWorkflowAssociation workflowAssoc = null;
            workflowAssoc = docLib.WorkflowAssociations.GetAssociationByName(

            if (workflowAssoc != null)
                                     workflowAssoc, workflowAssoc.AssociationData);

The above code will start the FolderContentWorkflow (which will be detailed in the next section). The WF will start when a new FolderContentType is added. The steps used to start the Workflow can be summarized as:

  • When a new item is created, handle the ItemAdded event.
  • Check if the item type is our FolderContentType.
  • If yes, locate the WF which was deployed already on the WSS server.
  • Start the WF using the Workflow Manager.

To start the WF when a FolderContentType is edited (updated), you need to change the type of the event, by overriding a different method in FolderContentTypeWorkflowStarter. This method is called "ItemUpdated".

In order to have this feature in your SharePoint site, you need to create a Class Library project which will contain FolderContentTypeWorkflowStarter, and after that, deploy the assembly. To accomplish this, you need to register the assembly into the GAC, and use the steps described in this article, or manually using the Microsoft.Sharepoint API using the EventReceivers property of SPList, something like:

docLib.EventReceivers.Add(SPEventReceiverType.ItemAdded, assemblyName, className);

Implementing the SharePoint Workflow

To create a new Workflow, we can use either Visual Studio or the SharePoint Designer. It is important to fill the name of the WF as "FolderContentWorkflow". This name is referenced in the starter class. It is out of the scope of this article to describe in details how to create WFs.

The final solution

We need to create a new FolderContentType:


The screenshot below shows the Workflow which was started from ContentTypeFolder (please note the "Completed" status in the FolderContentWorkflow column:



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Calin Tatar
Software Developer (Senior)
Romania Romania
TC is a passionate software engineer who lives & implements software technologies in Ireland.

You may also be interested in...

Comments and Discussions

QuestionAutomatically add Sharepoint subfolders when adding a new Folder Content Type Pin
dixi8417-Aug-10 0:33
memberdixi8417-Aug-10 0:33 
QuestionAutomatically add subfolders when adding a new folder content type Pin
Member 61317125-May-09 0:57
memberMember 61317125-May-09 0:57 
AnswerRe: Automatically add subfolders when adding a new folder content type Pin
Calin Tatar25-May-09 2:48
memberCalin Tatar25-May-09 2:48 
GeneralRe: Automatically add subfolders when adding a new folder content type Pin
Member 61317125-May-09 5:01
memberMember 61317125-May-09 5:01 
GeneralRe: Automatically add subfolders when adding a new folder content type Pin
Calin Tatar25-May-09 5:12
memberCalin Tatar25-May-09 5:12 
That was a sample code, you should adapt it for your requirements.
In order to write the feature, you have to reference the Sharepoint assemblies.

Have a look here[^] for a tutorial about writing WSS features.

PS. folders is a string array that contains the names for the subfolders to be created, you have to declare it.

GeneralRe: Automatically add subfolders when adding a new folder content type Pin
Member 61317125-May-09 21:55
memberMember 61317125-May-09 21:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 3 Feb 2009
Article Copyright 2009 by Calin Tatar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid