Creating a custom Visual Studio 2005 workflow for SharePointBuilding workflows for SharePoint is a challenging programming exercise, which is best tackled in small steps.
Once you have learned how to deploy your first workflow, you can concentrate on learning how to use and implement the Workflow Foundation activities that are specific to SharePoint.
Creating Visual Studio 2005 workflows for SharePoint is a 2-step process:
- Design and write code for the workflow in Visual Studio 2005.
- Deploy the workflow to a SharePoint server.
To create a custom Visual Studio 2005 workflow:
- In Visual Studio 2005, create a new Project that is based on the Sequential Workflow Librarytemplate.
- In the Solution Explorer, double-click the Workflow1.cs file to open the workflow designer.
- Drag a LogToHistoryListActivty from the Toolbox and drop it under theonWorkflowActivated1 activity of the workflow.
- Figure 1. Basic Sequential Workflow in Visual Studio 2005 for deployment to SharePoint.
- Select logToHistoryListActivity1, and set its HistoryDescription property in the Propertieswindow to The workflow has run..
- Build the workflow project.
Installing the workflow on SharePointYou can now proceed to deploying the Visual Studio 2005 workflow to SharePoint.
To deploy the Visual Studio workflow to SharePoint, you must:
- Make the compiled DLL of the workflow a strong named assembly by signing it with a strong name key.
- Deploy the assembly to the Global Assembly Cache (GAC) and retrieve its publicKeyToken. You will use the publicKeyToken in the workflow.xml file.
- Add the appropriate XML to the feature.xml and workflow.xml files.
- Modify the install.bat file by following the instructions in it. You can perform a Find and Replace to change the name of the workflow’s Feature folder and change localhost to point to your SharePoint server.
- Run the install.bat file to install the workflow on SharePoint.
Running the workflow on a SharePoint list or library
In the following example, I created a custom SharePoint list called MyFirstWorkflowList and associated it with the workflow. I named the workflow attached to the list MyFWF and set it to run whenever a new item is created.
In the figure below, you can see that a workflow instance has run on a newly created item.
Figure 2. A workflow instance has completed on a SharePoint list item.
If you click on the text Completed in the MyFWF column, you will open the Workflow Status page, where you will see the comment The workflow has run. in the Workflow History list.
Figure 3. The Workflow Status page of the workflow instance that ran on the SharePoint list item.