Authoring SharePoint 2007 Workflows using VS2008

Posted on 7/9/2008 @ 12:09 AM in #SharePoint by | Feedback | 14927 views

___________________________________________________________________________________________________________________

Table of Contents:

1. Setting up your environment for writing VS2005 workflows.

2. Writing an ultra basic workflow, deploying it, and slicing dicing how it worked.

3. Making that workflow more complex, adding if/else, and a bunch of activities that sort of make it more interesting.

4. Adding user interaction to that workflow using Infopath forms.

5. Authoring SharePoint 2007 Workflows using VS2008.
___________________________________________________________________________________________________________________

Microsoft introduced the new SharePoint 2007 workflow templates with VS2008. I'm sorry, but I don't like what they introduced. Sorry to be so blunt, but someone has to be honest. My #1 reason for not liking what they introduced is that the SharePoint 2007 WF Templates in VS2008 produce code that is not deployable. You cannot package it up as a feature or solution and hand it over to your infrastructure guy with a bad attitude. Sorry MSFT, but developers do not deploy - infrastructure & QA guys do.

Luckily, you can author your own WF template in VS2k8 - your own template that will allow you to very easily create features and solutions that any good project team would appreciate.

Here are the steps:

  1. Author a new class library project. I'm gonna call mine "SampleWorkflow".
  2. Add the following references -


  3. Delete the "Class1.cs" file.
  4. Create a folder structure as shown below:


  5. You will note in step #4 above that:
    1. I have strong named my class library.
    2. I have copied WSPBuilder in as well.
    3. I have created a folder structure, similar to the 12 directory - well established community standard, I am not willing to give it up until MSFT tools work.
    4. I have added an install.bat. Here is my install.bat -
    5.    1: @SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
         2: @SET GACUTIL="c:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe"
         3: @SET WSPPBUILDER="WspBuilder\WspBuilder.exe"
         4:  
         5: @echo off
         6: Echo Creating Solution Package
         7: %WSPPBUILDER% -outputpath solution -Excludepaths bin
         8:  
         9: Echo Retracting Solution
        10: stsadm -o retractsolution -name SampleWorkflow.wsp -immediate
        11: stsadm -o execadmsvcjobs
        12:  
        13: Echo Deleting Solution
        14: stsadm -o deletesolution -name SampleWorkflow.wsp
        15:  
        16: Echo Adding Solution
        17: stsadm -o addsolution -filename Solution\SampleWorkflow.wsp
        18:  
        19: Echo Deploying solution
        20: stsadm -o deploysolution -name SampleWorkflow.wsp -immediate -allowGacDeployment
        21: stsadm -o execadmsvcjobs
        22:  
        23: Echo Resetting IIS
        24: IISRESET
  6. Edit the Project's Build Events to call this Install.bat on every successful build.
  7. Close Visual Studio (LOL, yeah!).
  8. Now, open the .csproj file in Notepad, and make the following modifications -
    1. At the Project\PropertyGroup element, add the following element -
    2.    1: <ProjectTypeGuids>{14822709-B5A1-4724-98CA-57A101D1B079};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

    3. At the Project element, right below <Import Project = "$MSBuild .. ", add the following element
    4.    1: <Import Project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets" />

  9. Excellent, now reopen the CSProject, and add your first workflow as shown below:
  10. From the toolbox, drag drop the "onWorkflowActivated" activity under the "SharePoint workflow" area.
  11. Set the correlation token.
  12. You're all set !! For further steps around the process of  actually authoring the workflow, the steps are exactly similar to VS2005, and can be found here -

___________________________________________________________________________________________________________________

1. Setting up your environment for writing VS2005 workflows.

2. Writing an ultra basic workflow, deploying it, and slicing dicing how it worked.

3. Making that workflow more complex, adding if/else, and a bunch of activities that sort of make it more interesting.

4. Adding user interaction to that workflow using Infopath forms.

5. Authoring SharePoint 2007 Workflows using VS2008.
___________________________________________________________________________________________________________________

Sound off but keep it civil:

Older comments..


On 7/24/2008 8:57:38 AM dinger said ..
hello,


this is a great tutorial and i really look forward to trying it. one question i have is where did you get the wspbuilder.exe file to add to the project. i have downloaded the wspbuilder application from codeplex. i am figuring that i have to compile part of the wspbuilder solution, but i don't know what part to build.

thanks


On 7/24/2008 1:58:43 PM dinger said ..
Since my previous post, i have discovered that I downloaded the incorrect files from codeplex. I will now continue with testing out this workflow.

Thank you


On 7/31/2008 11:16:33 AM carl said ..
after adding the sequential workflow, I am getting the error -

the designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: Workflow1. The base class Workflow1 for the class needs to be an Activity

Any idea why I am recieving this error?


On 7/31/2008 11:30:07 AM carl said ..
figured it out - I was missing a reference in my project. double check all references to ensure everything is included.


On 7/31/2008 2:58:31 PM Sahil Malik said ..
carl - ur missing the system.drawing reference


On 7/31/2008 2:58:44 PM Sahil Malik said ..
Umm .. okay .. ju figgured it out!


On 12/10/2008 10:48:48 AM Keith said ..
Sahil.. How do you handle existing workflows when you are upgrading? Your batch retracts and deletes the solution before adding it back and deploying. If you had a long running workflow what issues would you run into? Thank you, Keith


On 2/5/2009 3:52:31 PM kiv said ..
I have followed the steps to create a workflow in vs2008 and deployed it as a feature in MOSS 2007. I am able to associate a list with the workflow. On modifying the task list i get the error message Failed on Start. Any ideas what could be causing that? Thanks.


On 2/9/2009 9:08:59 AM kiv said ..
The dll was not deployed to the gac. Once i deployed it to the gac the issue was resolved.


On 2/11/2009 8:16:28 PM Peter said ..
So what about the "SharePoint Workflow Package Generator" that comes with the VSTO Power Tools? (http://blogs.msdn.com/nikhil/archive/2008/03/03/vsto-power-tool-sharepoint-workflow-package-generator.aspx)

Wouldn't this tools help things?


On 7/15/2009 1:27:21 AM Hari said ..
I have followed the steps to create a workflow in VS2008 and deployed it in MOSS 2007. I have associated a list to the workflow. But workflow is throwing an error. The error which is logged in the log file is:


Workflow Infrastructure 88xr Unexpected WinWF Internal Error, terminating workflow Id# 6e10beea-04a6-4492-8b2d-3d7808d01687


07/14/2009 17:06:07.79 w3wp.exe (0x0128) 0x0B34 Windows SharePoint Services Workflow Infrastructure 98d4 Unexpected System.ArgumentNullException: Value cannot be null. Parameter name: uriString at System.Uri..ctor(String uriString) at Microsoft.SharePoint.SPSite..ctor(String requestUrl) at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties.<get_Site>b__0() at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state) at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties....


07/14/2009 17:06:07.79* w3wp.exe (0x0128) 0x0B34 Windows SharePoint Services Workflow Infrastructure 98d4 Unexpected ...get_Site() at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties.get_Web() at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties.get_Item() at SampleWorkflow.Workflow1.codeActivity1_ExecuteCode(Object sender, EventArgs e) at System.Workflow.ComponentModel.Activity.RaiseEvent(DependencyProperty dependencyEvent, Object sender, EventArgs e) at System.Workflow.Activities.CodeActivity.Execute(ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCo...


07/14/2009 17:06:07.79* w3wp.exe (0x0128) 0x0B34 Windows SharePoint Services Workflow Infrastructure 98d4 Unexpected ...reRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run()

Is it necessary that we always use Sharepoint 2007 Sequential workflow to create a custom workflow in sharepoint?


Thank you...


On 1/20/2010 5:17:09 AM Jakob Flygare said ..
I have build the project but the dll is not included in either the solution manifest nor is it in the wsp. Thus it will not be deployed to the GAC. What is missing here?


On 2/17/2010 1:08:13 PM Blue Diamond said ..
I have followed the steps above for VS 2008 but and add the workflow as in step 9, after that I am not able to perform step 10. I don't have the tab for SharePoint Workflow in the Toolbox. Any help