Winsmarts.com

Microsoft MVP

MVP Logo

Awarded the Microsoft MVP Award.

Hosted By

blah!bLaH!BLOG!!

Authoring SharePoint 2007 Workflows using VS2008

Posted on 7/9/2008 @ 12:09 AM in #Sharepoint | 10 comments | 10492 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.
___________________________________________________________________________________________________________________


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?

Please post your comments:


Your feedback will be submitted for moderation, and will appear after it is approved.

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Site designed and maintained by Sahil Malik | All Rights Reserved. ©2007 WinSmarts.com.