Hi everybody and my excuses for the long silence but the last weeks of the year and by that all the festivities, also took their tole one me :)
In this article I will show you how you can create a workflow in SharePoint Designer 2010, export it and then import it in Visual Studio 2010 for further extending.
One of the great new things in SharePoint Designer 2010 is the possibility to export created workflows to use them in Visual Studio 2010. Like this it's now much more easier for power users to design workflows and give them to a developer who can further extend this workflow in Visual Studio 2010.
1. Create a workflow in SharePoint Designer
Startup SPD and connect to your site collection. Go to 'Workflows' and click on 'Reusable workflow' to create a new reusable workflow.
Give it a name and a description and choose the content type for which this workflow will be available.
2. Design the workflow
You can now start using all the conditions and actions provided by SPD to create your workflow. I created a very simple workflow which will set the workflow status to 'Cancelled' if the current item's title field equals "Title1". Else the status will be set to 'Approved'.
You can click on 'Check for errors' if you want so you are sure that you used all components correctly.
Save the workflow. SPD will now create all the necessary files for the workflow.
3. Exporting the workflow
Now in SharePoint 2010 beta, you cannot just use the 'Save as Template' button to create a wsp file for this workflow. You would think this function works alright but when you try to import this wsp into a Visual Studio 2010 project, an error will appear saying "Parameter name - Relative path". This issue is known by Microsoft. It's due to a problem in the export function which is not handled correctly in Visual Studio.
A workaround for this, is to export the complete site as a template. To do this, click on your site collection on the left (the button with the house icon). On the top, in the ribbon, you can select 'Save as template'. This will launch the template creation aspx page. Choose a file name and template name. You don't need to 'Include Content'. Click ok to start the template creation.
After completion, click on the provided link to go to the 'user solution gallery'. From there, you can download the wsp file to your drive.
4. Importing the workflow wsp into Visual Studio 2010
Start Visual Studio and create a new SharePoint 2010 project of type 'Import Reusable Workflow'. Type in the URL to your site collection and on the next screen, point the wizard to the site template wsp file. The wizard will analyze this file and present you with a list of all the reusable workflows it could find.
Choose your new workflow and click Finish. This will load the workflow as a new project in the solution. As you can see, the template includes a feature, a package and the actual workflow including the xoml, the rules and cs code file.
Double clicking the xoml file will load the designer view. The names of the activities may not be the best chosen but at least the design itself is unchanged. Like in 2007, you can start adding activities and conditions.
The actual rules we defined in SPD, are stored in the rules file. No actual c# code is generated. Just to be clear, the workflows are based in .NET framework 3.5 and not on version 4.0.
You can now start to extend the workflow with custom code, create a wsp file and use it in your site collection.