Using and creating custom SharePoint workflows
While there are several ways to use and create workflows that run in SharePoint, you have two options when it comes to creating custom workflows for SharePoint:
- Create a SharePoint Designer workflow
- Create a Visual Studio workflow
Both types of workflows can run on InfoPath forms stored in SharePoint form libraries.
Retrieving InfoPath form data in a SharePoint Designer workflow
When you use SharePoint Designer to create custom workflows that run on InfoPath forms, your only option to retrieve form data from within the workflow is through promoted InfoPath form fields.
This means that when you publish an InfoPath form template to SharePoint, you have to promote the fields, that is, make them available as columns of the form library, so that the data that is stored in those fields are displayed in the columns when you save an InfoPath form in the form library.
A disadvantage of using this method is that InfoPath does not allow you to promote all types of fields. For example, when you promote a field from a repeating table, only the field in the first row of the repeating table will be displayed in the SharePoint form library column.
For an example of using this technique, see Automatically add a new item to a SharePoint list using InfoPath 2007 and a custom workflow.
Update Feb 22, 2009:
For an example of using a SharePoint Designer workflow to set the value of a field in an InfoPath form, see Set the value in an InfoPath form from a SharePoint Designer workflow.
Retrieving InfoPath form data in a Visual Studio workflow
When you use Visual Studio to create custom workflows that run on InfoPath forms, you have total flexibility when retrieving form data from within the workflow.
Ordinarily you use
workflowProperties.Item
to retrieve the item within a SharePoint list or library that the workflow is running on. To access an InfoPath form that a workflow is running on, you simply have to use the File property of the item that the workflow is running on:
SPFile file = workflowProperties.Item.File;
Once you have an SPFile object, you can retrieve the binary data associated with this object:
byte[] xmlFormData = file.OpenBinary();
If you want to then access data that is stored within the InfoPath form, you can load the binary data into an XPathDocument object
XPathDocument ipForm = null;
using (MemoryStream ms = new MemoryStream(xmlFormData))
{
ipForm = new XPathDocument(ms);
ms.Close();
}
and then use XPath expressions to get the data out of the XPathDocument object
XPathNavigator ipFormNav = ipForm.CreateNavigator();
XPathNavigator nodeNav = ipFormNav.SelectSingleNode(
"//my:field1", nsManager);
where nsManager is an XMLNamespaceManager object holding the XML namespaces for the InfoPath form.
For an example of using this technique, see How to use a Visual Studio workflow to submit data from an InfoPath form to a SharePoint list.

Comments to this post were closed 30 days after it was published.