Just a few quickies in case you want to export a SharePoint Designer Workflow straight into Visual Studio there are a few things that might save you quite some time. In this blog I try to cover the things I encounter.
First of all, if you want to import your globally reusable workflow using the Import Reusable Workflow you need to make sure it is published. If your workflow is not published before it’s saved as a template it will not be recognized in the import wizard, thus making it impossible to import it.
When creating the workflow with the SharePoint designer it is pretty easy to give a fancy name to the workflow, in my case it was called Provisioning Approval Workflow, saving it as a template doesn’t throw any error, then importing seems to work, however as soon as you try to package the new project it starts throwing errors like:
_Activity ‘RootWorkflowActivityWithData’ validation failed: Property ‘Name’ has invalid value. The identifier " is not a valid name._
So the x:Name attribute is not supporting a space in the name, that’s an easy fix, by changing it, however after doing so the assembly building fails because it tried to make a class called:
_public partial class Provisioning Approval Workflow_
You can start fixing those issues one by one, but also just before publishing and exporting the workflow replace any spaces in the name for _ so everything will compile right away.
Now there is one more minor thing before the project actually builds, it is missing references.
If you have custom workflow activities that might be expected behavior (just add them), but by default it is also missing the Microsoft.SharePoint.WorkflowActions. That one can be found on the location:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.WorkflowActions.dll and after adding that your imported workflow will most probably compile.
Once it compiles you might want to change the feature name because it still has a default Feature1 name. Also you might want to check the Elements.xml file in the Workflow object for the Name and Description (in the Name you can strip out any _ and return it as a fancy name. Also you can probably strip out the whole
<MetaData> block since that contains almost only empty elements (except for the StatusPageUrl that, if you don’t roll-out a custom StatusPageUrl can be left blank to get the default one). Also you can strip out the InstantiationUrl , ModificationUrl and StatusUrl since they will throw errors when executing the workflow (throwing an error like:
The workflow template has specified no FormURN for this page.). If you don’t throw out the MetaData block make sure to delete the AssociationCategories node because otherwise provisioning the Workflow to a ContentType.