Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007 (part 1/20).




By Serge Luca




Step 1/20.Creating and Testing the project

Download the code


One of the greatest innovations in Windows Sharepoint Service v3 and MOSS 2007 is the integration with Windows Workflow Foundation, a core component of the .Net Framework 3.0.

To have a general overview  of Windows Workflow Foundation, take a look at these interesting articles from David Chappell.

Introducing Microsoft Windows Workflow Foundation: An Early Look.

Understanding Workflow in Windows Sharepoint Services and the 2007 Microsoft Office System.

In this long series of articles, we will provide a step by step approach to building workflows in Sharepoint with both Microsoft Visual Studio and Microsoft Sharepoint designer.


2. Submitting an expense Report: the scenario


The workflow we are going to create step by step is an application that allows users to submit their expense reports; as soon as their expense report will be submitted, a workflow will be activated; this workflow will:


  • ·         Generate a unique identifier (a guid) for this expense report

  • ·         Check if the report must be submitted to approval : if the amount is less than 1000, the expense report will be automatically approved and the process is completed (status will be “autoapproved”)

  • ·         Find the user’s manager

  • ·         Create tasks for the manager to approve or reject the expense report

  • ·         Update the expense report status (“approved or “rejected”).


Before starting, make sure you have a team site with the following list:

A list named “Expense Reports” with following columns:


A list named “Managers” with the following columns:


(very important , make sure the Manager and Manager Of columns are of type Person or Group with the Show Field option as account )


Fill up the Managers list with the following values:



3.2 Creating the workflow


Before starting Visual Studio 2005, make sure the followings components have been installed:


  • ·         Visual Studio 2005 Extensions for Windows Workflow Foundation.

  • ·         Visual Studio 2005 Extensions for Windows Sharepoint services v.3

It’s time to create our first workflow: start Visual Studio 2005 and create a new project :

 select  Sharepoint project type and the Sequential Workflow Library  template. Name the project U2U.ExpenseReport:


In the solution Explorer, delete Workflow1.cs, and add a new workflow file:


Select sequential Workflow and name the file ExpenseReportWorkflow.cs:


Double click on ExpenseReportWorkflow.cs to visualize the workflow in the Workflow Designer

Take a look at the referenced assemblies in Solution Explorer:



3.2 Setting up  the Sharepoint activities 

The Sharepoint team provides a set of activities and most of them are compiled in the microsoft.sharepoint.WorkflowActions.dll that can be found in the  C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI folder.

Most activities are either activities derived from HandleExternalEventActivity which is a basic Workflow Foundation activity waiting for an Event or CallExternalMethod which is an activity calling a class implementing an interface (this class is called “local service”).

The communication between the WorkflowRuntime host (which in our case is Sharepoint) and the workflow follows the usual pattern defined by the Windows Workflow Foundation team:


  • ·         Sharepoint will communicate with the workflow by sending  events

  • ·         The workflow will invoke Sharepoint by calling a method on a dedicated interface that will redirect the call to the Sharepoint api.

The interfaces we will have to deal with are defined in the Microsoft.Sharepoint.Workflow namespace of the Microsoft.Sharepoint assembly and are decorated with ExtenalDataExchangeAttribue (see the Windows Services sdk):


  • ISharepointService
  • IListItemServices
  • ITaskServices
  • IWorkflowModificationservice


For Windows Workflow Foundation aficionados, it’s worth knowing that the WorkflowRuntime class is completely encapsulated and hidden by the Sharepoint framework; therefore we cannot add our own local /runtime services and invoke them from our custom activities as we usually do we host the workflow runtime ourselves.

To display the Sharepoint activities in Visual Studio Toolbox, let’s create a new tab: “Sharepoint activities” and drag & drop the Microsoft.sharepoint.WorkflowActions.dll on it (or use the toolbox  browse menu, but the first option is faster).


Many others activities are also available in the WorkflowActions assembly but their ToolboxItem attribute is set to false so that they won’t show up in the toolbox but they can be used with Microsoft Sharepoint Designer.


3.3 Finishing, deploying and testing our “hello world” workflow

The first activity in a Sharepoint workflow must be the Microsoft.SharePoint.WorkflowActions.OnWorkflowActivated activity.

Drag and drop an OnWorkflowActivated activity into the designer:


Set its CorrelationToken property as follows:

CorrelationToken are extensively used is in Workflow-Sharepoint programming and are an interesting way to logically group activities together; more details about this later…

To make sure our workflow will really work, let’s drag and drop a LogToListHistory activity after the onWorkflowActivated1 activity.


Set its HistoryOutcome property to “hello from Serge”:

It’s time to deploy our hello world workflow: workflows in Sharepoint must be deployed as  features, so we need to provide more details about our current feature in the feature.xml file .

Make sure the features code snippet are activated (the snippets are installed on C:\Program Files\Microsoft Visual Studio 8\Xml\1033\Snippets\Windows SharePoint Services Workflow, press CTL K + B to add this folder to the snippets; choose XML as the language).

Select the feature.xml file and use the feature snippet to insert the feature code:


Replace the Guid with a new Guid (use the create Guid tool in  Visual Studio Tools Menu-Create Guid menu, select registry format, click on “New Guid” Button, click on Copy and paste it in the feature.xml file).

Replace the Title and Description attributes with some meaningful information:

Sign the assembly: project properties-Signing– Check sign the assembly, select new, create a new file and rebuild the project.

The manifest file of the feature is workflow.xml: replace the existing content with the tags provided by the workflow snippet; set the Id with a generating a new Guid, provide a Name, a Description, and specify the CodeBesideClass.

Use Reflector to retrieve your assembly strong name and insert it into the CodeBesideAssembly attribute :


Remove any other tags.

The install.bat file will deploy our workflow by registering the assembly to the Gac by will installing and activating our feature to the site collection.

We need to specify the site collection in the install.bat file: replace “http://localhost “ string with your site collection url :


In my version of the install.bat, 3 occurrences have been replaced.

Next we need to specify our assembly name (that will also be our feature name here): replace the string “MyFeature” with the string “U2U.ExpenseReport”.


In my version of the install.bat file, 13 occurrences have been replaced. Save the file.

Start the install.bat and check any potential error message.

You can verify your workflow has been activated:  Site settings Menu-GalleriesWorkflows


Let’s make an association between our ExpenseReports list and the workflow :

Select the ExpenseReports list, go the List Settings: in Permission and Management, select Workflow settings:


Select Add a workflow and  select the Expense report Workflow ; type a unique name for the association like  ApproveReject :


Click on Ok.

Go to the ExpenseReports list add a new Expense Report:


Start the workflow menu associated with the item:



Click on the ApproveReject button.

Normally a new column the association has been added to the list; if everything is ok, the workflow status for the item is completed:

If you click on the Completed hyperlink, you’ll be redirected to the workflow history and you’ll see our message:

Congratulations !  In the next article we will implement the Submit expense Report scenario.

This hands-on training is the property of Redwood S.L sprl and may not be organized in class or in group without the prior written permission of Serge Luca. Should you wish to organize this hands-on training in your company or institution, please contact Serge Luca  first to enter into a licence agreement. Each trainer or teacher using this hands-on training should have a licence agreement. Please ask your trainer or Serge Luca whether he or she has entered into a licence agreement with Redwood S.L sprl.

The hyperlink to this hands-on training may be placed on your website for free, on the condition that the name Serge Luca is clearly mentioned in the reference. Please send us a mail containing the link to the web page our reference is used on.