Deploying a .NET, Visual Studio Workflow into a SharePoint List in 10 Easy Steps (Part 1 of 2): Creating the Workflow 

Tags: SharePoint Development

There is a lot of content on the web around custom Windows Workflow Foundation (WFF) workflows and how they integrate into SharePoint. However, I couldn't find a post or article that contained the basics steps to deploying a workflow that wasn't watered down with the useful, yet complicated intricacies and specifics that make it difficult to learn WFF for beginners. This post is my attempt to help those who tend to learn better by doing, rather than reading…


The workflow I'll be walking you through will bind to a SharePoint list, and when a new list item is added, the workflow will fire and create a new task in a Tasks list. This is a pretty basic example, but it serves to demonstrate the concept of creating and deploying workflows. This first part in the 2 part series walks you through creating the workflow in visual studio.


Part 1: Building Your Custom .NET Workflow


  1. Download and install Visual Studio Extensions for .NET 3.0 (WSS 3.0 Tools extensions may be needed as well, I can't remember).

    These extensions are required to create workflow projects with Visual Studio.

  2. Create a new SharePoint Sequential workflow called "NewTaskWorkflow".


    (Figure 1 – new project window showing SharePoint workflow template)

    You can create a sequential workflow under the "Workflow" section, rather than the "SharePoint" section, however, you will not get the feature files we'll use to deploy this to our SharePoint site.


    Notice the solution explorer has our feature files that will be used to install the workflow onto the SharePoint site. Also, the template gives us production deployment files that we can use to create a SharePoint Solution and deploy our workflow across the entire farm. For the sake of simplicity, I'm not going to demonstrate that concept now, and I will simply do a manual deployment of the feature files.


    (Figure 2 – workflow project's default configuration)

    Double click on Workflow1.cs and you'll be brought to the workflow designer interface. By default, only one workflow item is in the workflow, the onWorkflowActivated1 item. This is a good item to use if you need to set state upon initiation of the workflow.


    (Figure 3 – Workflow's drag and drop designer interface)

  3. Open the toolbox and drag the "Create Task" workflow activity onto our NewTaskWorkflow designer.


    (Figure 4 – project toolbox containing all available workflow activities)

  4. Notice the red exclamation point next to the new activity we just added. If you click on the activity and view the properties, you'll notice there's a property that we need to take action on:


    (Figure 5 – the CorrelationToken property is not set)

    Click in the box and set the token to something like "TaskToken". After you set the token to "TaskToken", you'll notice a plus sign appear to the left of the property. Click the plus sign and select the drop down and set the ownership to Workflow1. Thereafter, the red exclamation point will go away.

    (Figure 6)

     You can use these tokens to associate a set of activities with one another. A good way to think about it is a particular workflow may have several paths of events, wherein each path's activities should be "correlated" to one another so their outputs don't affect other paths and activities that are not related. Specifically, these tokens refer back to the SharePoint list items, in this case the specific task. Click here to read more on correlation tokens.

  5. Now that our activity is correlated, we need to alter it in some way so you know that our code can interact with the workflow. In addition to this, we need to do some tricks to get the createTask action to function. Let's start by setting the TaskID and TaskProperties properties of the createTask activity. Click on each property and select the ... icon and enter "myTaskID" and "myTaskProperties" respectively:

    (Figure 7)

    For the sake of demonstration, we'll just set the Title column of the task to a unique string and the task ID. Right click on the createTask1 activity and choose "Generate Handlers". This will wire-up a method that is invoked when the workflow reaches this activity. Here is where I'll set the title of the task and the ID.


    (Figure 8 – handler that sets the title of the new task item the will be generated)


If you did these steps you have a working workflow that you can now deploy into SharePoint! It's pretty easy huh?


My next post will contain the steps necessary to deploy the workflow we just created. I'll also at that point publish my project source for your viewing pleasure. Stay tuned, I should have part two up in the next couple days.


Cheers!

 
Posted by Phillip S. Wicklund on 9-Feb-08
18  Comments  |  Trackback Url  | 0  Link to this post | Bookmark this post with:        
 
Failed to render control: Value does not fall within the expected range.

Comments


Nice Post!commented onMonday, 11-Feb-2008
Great post. Please post the deployement steps soon.


no workflow designer interfacecommented onWednesday, 27-Feb-2008
I don't get a "workflow designer interface;" when I click on Workflow1.cs, I see code.


(RE) no workflow designer interfacecommented onWednesday, 2-Apr-2008
Did you download my project source? If you did, make sure the visual studio extensions were properly installed. If they were not, you won't see the designer interface. Phil


Good Article! but have some doubt.commented onMonday, 7-Apr-2008
after installtion of VS2005 extensions, designer interface is shown, but i am getting window workflow instead of sharepoint workflow. Is there anything that need to be insatalled? i do not have WSS installed on my machine. is this the cause of problem? Please advise me.


(RE) Good Article! but have some doubt.commented onThursday, 10-Apr-2008
Yes - I have seen this problem before too. Are you on VS 2008? If you are, there maybe a different set of extensions or something. Either way, it shouldn't matter if you have the windows workflow template, and not the sharepoint workflow template. Both deploy just fine into sharepoint. The sharepoint one just gives you those deployment files and a few references already added to the project. Add a reference to Microsoft.SharePoint.WorkflowActions and manually created those deployment files and you should be good to go. Phil


Jasoncommented onSunday, 22-Jun-2008
God bless you for this post. There are SO many useless and incomplete posts out there. Yours is the first one to actually help me get a WF deployed. You did it the right way. You provided a simple starting point. Almost everybody else has written a thesis paper with all sorts of crap that doesn't apply and it's just garbage that's confusing every beginner searching for help. Thanks again! And, yes, after 4 weeks of trying to get this all to work using even Microsoft sources, 10 minutes after reading your post, I have deployed a simple, yet working version. Now I can focus on building upon what I have and finishing this thing.


adnxswezegcommented onThursday, 28-Aug-2008
Hello my friend, your site is very good! http://uoqwajpmwrd.com


Nikecommented onSaturday, 15-Nov-2008
Great info. Thanks!


Nikecommented onSaturday, 15-Nov-2008
Great info. Thanks!


Lindacommented onSaturday, 15-Nov-2008
great nice imformation!


Madlencommented onSaturday, 15-Nov-2008
Very nice site!


Jeksoncommented onSunday, 16-Nov-2008
I have bookmarked this page too. Great resource.


Tomcommented onSunday, 16-Nov-2008
Very nice site!


Patrikcommented onSunday, 16-Nov-2008
A great resource - many thanks!


Elencommented onMonday, 17-Nov-2008
Very nice site!


Dikecommented onMonday, 17-Nov-2008
Good job of research. Thanks for the informative post.


Bertacommented onMonday, 17-Nov-2008
Hi, thanks for the great information.


Garycommented onMonday, 17-Nov-2008
A great resource - many thanks!

Name:
URL:
Email:
Comments: