Wednesday, 31 October 2007

First steps to authoring Visual Studio Workflows for SharePoint

The following 4 posts from Sahil Malik I believe give you a few good sessions on authoring workflow with Visual Studio.

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.

Pitfalls you might encounter:

Pitfall 1: Value does not fall within expected range.

This is a problem with the workflow.xml definition file. The TaskListContentTypeId is defined in the snippet as 0x000. This does not work and gives this error when you try to access the workflow from the list settings.

I found a solution to this problem in this post:

"Value does not fall within expected range" Most probably due to a wrong value for the TaskListContentTypeID in the workflow.xml, I don't know what are the possible values but this one works: "0x01080100C9C9515DE4E24001905074F980F93160"

More details on this are found here: Workflow Task Forms (Windows SharePoint Services)

Pitfall 2: Unexpected error

This is quite an informative error. You'll need to access the logs to determine what happened. Again this is a problem with the default workflow.xml snippet. I found an error that the MyAssocForm.aspx does not exist (and when I checked in the layouts directly it really doesn't exist). So in the workflow.xml you need to remove references to:

  • MyAssocForm.aspx
  • MyInitForm.aspx
  • MyModForm.aspx

The WrkStat.aspx exists, so we'll leave it there. The above pages need to be defined for more advanced workflows.

Pitfall 3: Workflow install.bat works flawlessly but you get Failed to Start in the workflow

Could not load file or assembly Load Workflow Assembly: System.IO.FileNotFoundException: Could not load file or assembly 'xxxxxx, Version=, Culture=neutral, PublicKeyToken=xxxxxxxxxxx' or one of its dependencies.

This was the problem which caused much frustration, whining, pulling hair and lots of waste of time.

This is usually a problem either with feature.xml or highly likely workflow.xml. My problem was that the workflow.xml file in the CodeBesideClass I had one single character which was lowercase instead of uppercase. Example I had TestofWorkflow instead of TestOfWorkflow. Obviously you can imagine, the reaction I had when I managed to solve this problem.

Hopefully some of you can find this blog and solve their problems much faster than myself.