Porting SharePoint Designer Workflows to Visual Studio

Porting SharePoint Designer Workflows to Visual Studio

Rate This
  • Comments 42

Eilene Hey everyone,

A lot of people ask if SPD workflows can be customized in Visual Studio so that you can deploy it as a reusable workflow template or add some code to it, and our official answer is that it’s not supported. But... it doesn’t mean it’s not possible to some extent;). In reality, an SPD workflow is a Workflow Foundation XOML file that’s compiled on the fly, so this file can be opened in the Visual Studio Extensions for WF. Today, I’ll show you how to get started;). (It’ll be our little secret!)

I’d strongly recommend having a basic understanding of how VS workflows work prior to reading this (I will probably gloss over some of the VS specific details;)). For general information about building VS workflows, the SharePoint blog is a good place to start.

Also, I should note that this works for workflows that do not have forms. Adding forms can be complex, so I’ll try to cover them in a separate post.

Step 1: Create a VS Workflow Project

In VS, go to File > New and select either a SharePoint Workflow Project (from the WSS or MOSS SDKs) or Workflow Foundation project. You will need Visual Studio Extensions for Workflow Foundation installed.

Step 2: Copy the SPD .xoml and .rules files into the VS project

image

With the new project in place, we’ll start porting the SPD xoml over to VS. First we need to extract the appropriate workflow files from SPD. To do this, open SPD and go to the Folder List. Right-click on the workflow that you want and choose the Publish Selected Files... option.

In the Remote Web Site tab of the dialog that appears, select the File System radio button and choose a local location on your computer. This will create a folder called Workflows on your file system in the location specified.

When you have these files, rename the .rules file (if you have one) from *.xoml.rules to *.rules. Then add the .xoml and .rules files to your VS project. If you double click on the .xoml file in the Solution Explorer, the WF workflow designer should open, and you should see all your SPD actions in place.

Step 3: Generate a .cs file under the XOML (optional)

If you want to add code behind your XOML, you’ll need a .cs file to go with it. By default, the copied XOML won’t come with this. To generate one, just bind a function to one of the activities in the designer. OnWorkflowActivated is there by default, so try typing an event handler name to its Invoke property. The .cs file created should automatically initialize the namespace and class name to match your XOML. If you don’t like the default names, change the attributes in the first line of the XOML in an XML editor before generating the file:

<ns0:RootWorkflowActivityWithData x:Class="Namespace.ClassName" ...>

Step 4: Deploy and debug the workflow

Fill out the rest of your deployment files and deploy the template as a SharePoint Feature the same way as with any VS workflow, then associate it for use. Since SPD workflows weren’t designed to be ported over, expect some kinks that you’ll have to debug through. But hopefully, the workflow provides enough of a base there to work through them, and with the ability to code, you can find some nifty workarounds;).

Hope this helps!
Eilene

  • I just deployed a SPD workflow to a list that was migrated from SharePoint 2003.  All new items will start the workflow automatically, but I need a way to start the workflow for all existing items manually (not all list items).  Is there a way to start workflows in bulk, instead of going to each list item and clicking start workflow?

  • Erika please tell us how to add forms to this project.

  • I am having same problem as Tina . Where and how do we initialize base variables in workflow? Your reaponse will be appriciated. Thanks,

  • Hi Eilene,

    Great post. Can you please explain where to initialize base variables in workflow? Same question that been asked by Tina and Canadian.

    Thank you in advance.

  • Body: I found a few noteworthy posts this morning while sucking down some coffee trying to wake up (rough

  • Hello ,

    My question is about Custom WorkFlows Actions/Activities in the SharePoint designer.

    In SPD an action is represented by a sentence. The properties are blue and underlined.

    The properties are, under the hood, represented by so called "DesignerTypes". Standard there are designerTypes for email, listfields, ...

    (so far nothing new)

    I am developping a custom WorkFlow Activity and want to fill in a property for which I can not use the standard DesignerTypes.

    Question: Can I and how can I build and register custom DesignerTypes.

    Thanks in advance

    Frank Lange

  • Después de algún tiempo sin postear el habitual recopilatorio de recursos interesantes de WSS 3.0 &amp;

  • Hi

    Thanks for your sharing!

    I did it following your post

    But when I double clicked on the .xoml file in the Solution Explorer,a message told me:

    "

    error loading workflow

    "

    my configue

    vs2005

    Visual Studio 2005 Extensions for Windows Workflow Foundation Beta 2_2(EN)

    how to deal with it

    thanks a lot

  • Direkter Download: SPPD-074-2007-07-12 [00:00] Intro [00:00] Buchtipps Microsoft Office SharePoint Server

  • I have the same issue as doudou -- after I publish my workflow and add it to a Workflow VS project, I get an error when trying to open it in designer: "Could not deserialize object. The type "Microsoft.Sharepoint.WorkflowActions.RootWorkflowActivityWithData" could not be resolved. Then I can't bind to create the cs. Does anyone know the resolution to this? Thanks.

  • Found the issue -- I was using the Workflow => Sequential Workflow Library project template. Instead, I am now using the WSS => Sharepoint Sequential Workflow Library template that comes with the WSS3 Workflow Starter Kit, and that works much better. Thanks for the post!

  • My File... New... doesn't list anything like "SharePoint Workflow Project." I can create a new C#/VB Workflow project, but I haven't had any luck that route. I've installed both the MOSS and WSS SDKs and am using VS 2005. Can someone tell me how to get "SharePoint Workflow Project" listed as an option? I'd really like to be able to run through this example. Thanks

  • I to would like to have Sharepoint Workflow Project listed as option in VS 2008. How do I get there?

  • I'm not sure if it is the exact same as used in this example, but I used the "Sharepoint Sequential Workflow Library" template that came with the "Workflow Developer Starter Kit for WSS 3.0" (not the WSS SDK), and it worked well for me. Downloadable at http://www.microsoft.com/downloads/details.aspx?familyid=5ddf902d-95b1-4640-b9e4-45440dc388d9

  • Todd Bleeker of Mindsharp, http://mindsharpblog.com/todd did a presentation of this at the SharePoint Conference 2008, Seattle. It was a community effort to get it working. More information can be found at: http://mindsharpblogs/paul.

Page 2 of 3 (42 items) 123
Leave a Comment
  • Please add 4 and 6 and type the answer here:
  • Post