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.
- 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.]
- Open the code view of your new workflow (*.cs)
- Add a using statements to the top of the file, after the existing using statements
- using Microsoft.SharePoint
- using Microsoft.SharePoint.Workflow
- using Microsoft.SharePoint.WorkflowActions
- Change the class to derive from SharePointSequentialWorkflowActivity instead of SequentialWorkflowActivity.
- Save your work and close the file.
- Open the design view of the workflow(*.cs [Design])
- Drop the onWorkflowActivated activity on the workflow surface.
- Double click on the onWorkflowActivated activity to create the invoked code behind.
- Save the file and then close the design view (*.cs [Design])
- Open the designer.cs file for the workflow (*.designer.cs) (It’s stacked underneath the *.cs file of the workflow by default.)
- Add a using statement to the top of the file after the existing using statements
- using Microsoft.SharePoint.Workflow;
- Add two variable declarations above the onWorkflowActivated1 definition
- public Guid workflowId = default(System.Guid);
- public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
- Expand the “Designer generated code” segment.
- After the line in InitializeComponent() which reads “this.CanModifyActivities = true;” add the following:
- System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind();
- System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind();
- activitybind2.Name = “myWorkflowName”;
- activitybind2.Path = “workflowId”;
- activitybind1.Name = “myWorkflowName”;
- activitybind1.Path = “workflowProperties”
- After the line in InitializeComponent() which reads “this.onWorkflowActivated1.Invoked += new System.EventHandler(this.onWorkflowActivated1_Invoked) add the following:
- this.onWorkflowActivated1.SetBinding(Microsoft.SharePoint.WorkflowActions.OnWorkflowActivated.WorkflowIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2)));
- this.onWorkflowActivated1.SetBinding(Microsoft.SharePoint.WorkflowActions.OnWorkflowActivated.WorkflowPropertiesProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1)));
- Save the *.designer.cs file.
- Open the design view of the workflow (*.cs [Design])
- Click on the CorrelationToken property and type ‘workflowToken’.
- Expand CorrelationToken and in the OwnerActivityName that appears beneath it select the name of your workflow.
- Save the file.
- 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.
Thanks very much !!
This is still a problem in VS2008 SP1!