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


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!

  • In molti di noi ci siamo chiesti se i workflow creati all'interno di SharePoint Designer 2007 siano o

  • Siguiendo con la serie de post sobre recursos de WSS 3.0 &amp; MOSS que iniciamos con las entregas I

  • Buchtipps Microsoft Office SharePoint Server 2007 - Das Handbuch von Bill English Beginning SharePoint

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

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

  • Hi Eilene,

    great post, thank you!

    Can you please give me informations about processing a workflow build in SPD having forms!

    Thank you,


  • You've been kicked (a good thing) - Trackback from SharePointKicks.com

  • 在新的SharePoint环境中,我们可以借助SharePoint Designer非常轻松的为某个列表设计并加载一个工作流。 这种方式的优点是快捷方便,无需任何代码,支持条件判断和多级流程,并且微软提供了丰富的操作选项

  • 如何把SharePoint Designer中设计的工作流导入VS2005里。

  • When I deploy this kind of workflow, I realized that at runtime the workflow InitiationData is always null.

    And thats why the workflow always fails if I dont have Initiation form.

    anyone help?

  • Ah, I forgot to mention that the ApplyActivation needs non-null init data to work correctly.  

    If you have no initiation form, remove the ApplyActivation activity and initialize base variables with the following code early in your workflow:

    __context = new WorkflowContext();


               __list = __initParams.List.ToString();

               __item = __initParams.ItemId;

               __workflowId = __initParams.WorkflowId;

    Hope this helps,


  • In the last couple of days a huge amount of interesting posts are posted. And in case you didn&#39;t

  • The fact that you can't include custom workflows in a site template to me is a HUGE design flaw.  Why would you want to write a workflow that can only be used on the site it was designed on?  Seriously, I love the ease of the design process, but without a better deployment process it makes the whole thing useless.

  • Before I start there is a good guide to transforming a SharePoint Designer workflow to a visual studio

  • I'm fairly new to Workflows..

    When I generate cs file like the way it was described, it generated a file with .xoml.cs extension..

    Also this is the class name that I have, not sure where the ROOT came from.

    partial class ROOT : Microsoft.SharePoint.WorkflowActions.RootWorkflowActivityWithData

    I removed the Applyactivation activity, but not sure where to plug in this code..

    __context = new WorkflowContext();


              __list = __initParams.List.ToString();

              __item = __initParams.ItemId;

              __workflowId = __initParams.WorkflowId;

    Appreciate your reply

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