Share via


Porting SharePoint Designer Workflows to Visual Studio

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

Comments

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

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

  • Anonymous
    July 12, 2007
    Buchtipps Microsoft Office SharePoint Server 2007 - Das Handbuch von Bill English Beginning SharePoint

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

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

  • Anonymous
    July 15, 2007
    Hi Eilene, great post, thank you! Can you please give me informations about processing a workflow build in SPD having forms! Thank you, Maddin

  • Anonymous
    July 17, 2007
    You've been kicked (a good thing) - Trackback from SharePointKicks.com

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

  • Anonymous
    July 18, 2007
    如何把SharePoint Designer中设计的工作流导入VS2005里。

  • Anonymous
    July 21, 2007
    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?

  • Anonymous
    July 25, 2007
    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(); __context.Initialize(__initParams);            __list = __initParams.List.ToString();            __item = __initParams.ItemId;            __workflowId = __initParams.WorkflowId; Hope this helps, Eilene

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

  • Anonymous
    September 06, 2007
    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.

  • Anonymous
    September 17, 2007
    Before I start there is a good guide to transforming a SharePoint Designer workflow to a visual studio

  • Anonymous
    September 18, 2007
    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(); __context.Initialize(__initParams);           __list = __initParams.List.ToString();           __item = __initParams.ItemId;           __workflowId = __initParams.WorkflowId; Appreciate your reply

  • Anonymous
    September 19, 2007
    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?

  • Anonymous
    October 04, 2007
    Erika please tell us how to add forms to this project.

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

  • Anonymous
    October 19, 2007
    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.

  • Anonymous
    October 22, 2007
    The comment has been removed

  • Anonymous
    October 24, 2007
    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

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

  • Anonymous
    November 08, 2007
    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

  • Anonymous
    January 09, 2008
    Direkter Download: SPPD-074-2007-07-12 [00:00] Intro [00:00] Buchtipps Microsoft Office SharePoint Server

  • Anonymous
    February 06, 2008
    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.

  • Anonymous
    February 06, 2008
    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!

  • Anonymous
    February 13, 2008
    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

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

  • Anonymous
    February 26, 2008
    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

  • Anonymous
    March 04, 2008
    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.

  • Anonymous
    April 07, 2008
    Thanks alot, this saved my day

  • Anonymous
    May 07, 2008
    Body: SharePoint Designer Team Blog article on moving SharePoint Designer Workflows into Visual Studio

  • Anonymous
    May 15, 2008
    Body: So I am developing a sequential SharePoint workflow right now. The process I&#39;ve followed for

  • Anonymous
    May 31, 2008
    在新的SharePoint环境中,我们可以借助SharePointDesigner非常轻松的为某个列表设计并加载一个工作流。 这种方式的优点是快捷方便,无需任何代码,支持条件判断和多级流程,并且微...

  • Anonymous
    June 12, 2008
    Hi,   Can you please explain how to move the MOSS designer workflow from one MOSS server to Another server?

  • Anonymous
    June 27, 2008
    Hi, I am trying to develop a database form and save data into the server (SQL Server 2005) but it's not working. No error meggage is generated. When I post data it seemed to save in db but no data in db is going. I am using data view and inserted selected fields as single-item view. Can anybody help my why it's not working? Thanks in advance Maksuda...

  • Anonymous
    July 21, 2008
    Great post!! Thank you!!!! :)

  • Anonymous
    August 18, 2008
    J'ai posté récemment sur la notion des "Custom Activity" avec SharePoint Designer (SPD). Sujet délicat

  • Anonymous
    August 22, 2008
    Je travaille actuellement sur le développement d'un workflow qui automatise le transfert des fichiers d'un site web à un autre. j'ai créé un formulaire pour les paramètres d'entrés, mais le workflow ne charge pas les paramètres du formulaire, comment dois je faire? Tout aide est la bienvenue Merci d'avance

  • Anonymous
    September 16, 2008
    ha ha thanks a lot. It's very big secret. ^_^

  • Anonymous
    June 08, 2009
    Direkter Download: SPPD-074-2007-07-12 [00:00] Intro [00:00] Buchtipps Microsoft Office SharePoint Server

  • Anonymous
    October 08, 2013
    nice post