Skip to content

Adding the second workflow to a SharePoint Workflow Assembly

With the  2007 Office System: Enterprise Content Management Starter Kit (ECMsk), you get a project type that will create a SharePoint aware workflow (in either sequential or state machine format.)  However, if you want more than one SharePoint workflow in the same assembly you’ve got a problem.  The ECMsk (at least in Beta2TR which is the latest publicly available version as of this writing) doesn’t add the project item type into Visual Studio so you can’t create a second workflow easily.  Great.  Here’s how to do it by hand.

Help Your SharePoint User
  1. Create a workflow of your choice.  Choose the option indicated (code) not the one indicated (with code separation).  [Note: I used sequential workflow for my example – and technically this should be possible with code separation I just didn’t test the steps, yet.]
  2. Open the code view of your new workflow (*.cs)
  3. Add a using statements to the top of the file, after the existing using statements
  4. using Microsoft.SharePoint
  5. using Microsoft.SharePoint.Workflow
  6. using Microsoft.SharePoint.WorkflowActions
  7. Change the class to derive from SharePointSequentialWorkflowActivity instead of SequentialWorkflowActivity.
  8. Save your work and close the file.
  9. Open the design view of the workflow(*.cs [Design])
  10. Drop the onWorkflowActivated activity on the workflow surface.
  11. Double click on the onWorkflowActivated activity to create the invoked code behind.
  12. Save the file and then close the design view (*.cs [Design])
  13. Open the designer.cs file for the workflow (*.designer.cs) (It’s stacked underneath the *.cs file of the workflow by default.)
  14. Add a using statement to the top of the file after the existing using statements
  15. using Microsoft.SharePoint.Workflow;
  16. Add two variable declarations above the onWorkflowActivated1 definition
  17. public Guid workflowId = default(System.Guid);
  18. public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
  19. Expand the “Designer generated code” segment.
  20. After the line in InitializeComponent() which reads “this.CanModifyActivities = true;” add the following:
  21. System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind();
  22. System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind();
  23. activitybind2.Name = “myWorkflowName”;
  24. activitybind2.Path = “workflowId”;
  25. activitybind1.Name = “myWorkflowName”;
  26. activitybind1.Path = “workflowProperties”
  27. After the line in InitializeComponent() which reads “this.onWorkflowActivated1.Invoked += new System.EventHandler(this.onWorkflowActivated1_Invoked) add the following:
  28. this.onWorkflowActivated1.SetBinding(Microsoft.SharePoint.WorkflowActions.OnWorkflowActivated.WorkflowIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2)));
  29. this.onWorkflowActivated1.SetBinding(Microsoft.SharePoint.WorkflowActions.OnWorkflowActivated.WorkflowPropertiesProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1)));
  30. Save the *.designer.cs file.
  31. Open the design view of the workflow (*.cs [Design])
  32. Click on the CorrelationToken property and type ‘workflowToken’.
  33. Expand CorrelationToken and in the OwnerActivityName that appears beneath it select the name of your workflow.
  34. Save the file.
  35. You’re ready to build.  Press Ctrl-Shift-B to build – and your new workflow should just work.

Not as simple as it should be – and I have no way of knowing if this is a supported (or supportable) way of getting a standard workflow to work as a SharePoint workflow – but it’s worked thus far in my testing.


  1. This is still a problem in VS2008 SP1!

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share this: