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 (42)

  1. Igor Macori says:

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

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

  3. Buchtipps Microsoft Office SharePoint Server 2007 – Das Handbuch von Bill English Beginning SharePoint

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

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

  6. Maddin says:

    Hi Eilene,

    great post, thank you!

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

    Thank you,

    Maddin

  7. You’ve been kicked (a good thing) – Trackback from SharePointKicks.com

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

  9. 勤勤同学 says:

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

  10. pkarpati says:

    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?

  11. Eilene Hao says:

    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

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

  13. Josh says:

    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.

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

  15. Tina says:

    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

  16. Miles says:

    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?

  17. uk4sh says:

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

  18. Canadian says:

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

  19. Gopal says:

    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.

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

  21. Frank says:

    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

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

  23. doudou says:

    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

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

  25. lys says:

    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.

  26. lys says:

    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!

  27. arf says:

    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

  28. dr says:

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

  29. lys says:

    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

  30. 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.

  31. Thanks alot, this saved my day

  32. Body: SharePoint Designer Team Blog article on moving SharePoint Designer Workflows into Visual Studio

  33. Body: So I am developing a sequential SharePoint workflow right now. The process I&#39;ve followed for

  34. 晃晃悠悠 says:

    在新的SharePoint环境中,我们可以借助SharePointDesigner非常轻松的为某个列表设计并加载一个工作流。

    这种方式的优点是快捷方便,无需任何代码,支持条件判断和多级流程,并且微…

  35. Senthamil says:

    Hi,

      Can you please explain how to move the MOSS designer workflow from one MOSS server to Another server?

  36. Maksuda says:

    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…

  37. Marco says:

    Great post!!

    Thank you!!!! 🙂

  38. J’ai posté récemment sur la notion des "Custom Activity" avec SharePoint Designer (SPD). Sujet délicat

  39. Mamadou says:

    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

  40. Vinci says:

    ha ha thanks a lot. It’s very big secret. ^_^

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