SharePoint 2007 and Windows WorkFlow Foundation: Integrating Divergent Worlds
Deploying and Using the WorkFlow
Because the assembly of the workflow generated by the compilation in Visual Studio must be installed in the Global Assembly Cache (GAC), it needs to be signed as strong. You can use the standard Visual Studio 2005 infrastructure to sign it or the sn tool with the parameter -T. After the compilation is complete, you can use the gacutil tool to install the assembly in the GAC.
You use features to deploy workflows in SharePoint. As a new paradigm in SharePoint 2007, the feature was created as a way to encapsulate solutions and functionality for ease of deployment. Additionally, it provides a mechanism by which developers can package the files needed for a solution (as a workflow) intended for distribution.
<?xml version="1.0" encoding="utf-8" ?> <Feature Id="B2196C5B-1579-4bb7-B23E-01DC6A898ABC" Title="JupiterMediaWorkFlow" Description="Example WorkFlow" Version="18.104.22.168" Scope="Site" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests> <ElementManifest Location="Flow.xml" /> </ElementManifests> <Properties> <Property Key="GloballyAvailable" Value="true" /> </Properties> </Feature>
The Feature Id parameter is a Windows GUID that you can fashion with the GUID Generator component included in Visual Studio. A second file called Flow.xml, with the following code, defines the WorkFlow for SharePoint:
<?xml version="1.0" encoding="utf-8" ?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Workflow Name="JupiterMediaWorkFlow" Description="Example WorkFlow" Id="B2196C5B-1579-4bb7-B23E-01DC6A898ABC" CodeBesideClass="JupiterMediaWF.Workflow1" CodeBesideAssembly="JupiterMediaWF, Version=22.214.171.124, Culture=neutral, PublicKeyToken=99ca3967f3ef49e3"> <MetaData> <StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl> </MetaData> </Workflow> </Elements>
Copy both files to a new directory under the hive:
C:\Program Files\Common Files\Microsoft Shared\ web server extensions\12\TEMPLATE\FEATURES\JupiterWF
And install and activate the workflow using the SharePoint Administrators tool stsadm, with the following syntax:
To install the workflow:
C:\Documents and Settings\Administrator>"C:\Program Files\ Common Files\Microsoft Shared\web server extensions\12\BIN\ STSADM.EXE" -o activatefeature -name JupiterWF -force
To activate the workflow:
C:\Documents and Settings\Administrator>"C:\Program Files\ Common Files\Microsoft Shared\web server extensions\12\BIN\ STSADM.EXE" -o installfeature -name JupiterWF -force
At this point, you must link the workflow with the document library where it will operate (see Figure 3).
Figure 3. Setup of the Workflow in a Document Library
From the Document Library Settings page, proceed to Workflow Settings and, using the page Add a Workflow, select the workflow from the ComboBox. Give it a name, decide on a List to be used for its tasks and another one for the History (either use an existing list or create a new one), and select the start options (you can start it manually or automatically).
After creating a new document in the library, the user can utilize the context menu of the element to proceed to the page where he or she can select and activate the workflow (see Figure 4).
Figure 4. Activating a WorkFlow for a Document
Multiple workflows can run simultaneously on the same item, but only one instance of a specific workflow can run on a specific item at any given time. At the end of the working process of the flow, the result appear in the properties page of the document (see Figure 5).
Figure 5. Properties of the Document After Completing the WorkFlow
Note: In the properties page, the workflow has made a count of the vowels in the document's name and has altered its title to include the counter.
Integrating Divergent Worlds
The interaction between the Windows WorkFlow Foundation and Microsoft SharePoint 2007 offers an excellent way to attach business processes to items, and it provides the opportunity to control almost any aspect of a document's lifecycle and user interaction within SharePoint. A workflow can be as simple or complex as your business process requires, and it can be initiated either by users or automatically based on some event.
The architecture of the Foundation and its implementation in SharePoint allows for substantial flexibility to make changes in the business layers. It provides the option of reuse without having to alter the portal's deep infrastructure and unlocks new prospects for software architects, developers, and system administrators.
Download the Code
You can download the example workflow here.
About the Author
Gustavo Velez is a MCSD senior application developer for Winvision, a Microsoft Gold Partner in the Netherlands. He has many years' experience in developing Windows and Office applications, and more than four years of daily programming experience with SharePoint. Gustavo's articles can be found in many leading trade magazines and he's pleased to be Webmaster of www.gavd.net/servers, the only Spanish language-dedicated SharePoint site.
Page 2 of 2