Retrieve an InfoPath field in a SharePoint workflow

Learn how you can retrieve a field's value from InfoPath in a SharePoint workflow (SharePoint Designer workflow or Visual Studio workflow) that runs on that InfoPath form in a SharePoint form library.


SharePoint InfoPath 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 SharePoint workflows:

  1. Create a SharePoint Designer workflow
  2. Create a SharePoint workflow in Visual Studio

Both types of SharePoint workflows can run on InfoPath forms stored in SharePoint form libraries.

Retrieve InfoPath field 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 SharePoint 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 an InfoPath 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.

Retrieve InfoPath field in a SharePoint workflow created in Visual Studio

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


to retrieve the item within a SharePoint list or library that the workflow is running on. To access an InfoPath form that a SharePoint 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 InfoPath fields, you can load the binary data into an XPathDocument object

XPathDocument ipForm = null;
using (MemoryStream ms = new MemoryStream(xmlFormData))
  ipForm = new XPathDocument(ms);

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.


Related Posts


Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.