The interaction with users involved in a workflow in Microsoft Office SharePoint Server 2007 can be accomplished by using Microsoft Office InfoPath 2007 forms. The benefit of using Office InfoPath 2007 forms instead of ASPX pages is that the former can also be displayed by the 2007 Microsoft Office system clients. In this Office Visual How To, I'll work out a small custom workflow that shows the possible role of InfoPath 2007 forms.
You can display four types of Office InfoPath 2007 forms in SharePoint Server 2007:
Association forms are displayed when the workflow template is associated with a list, a document library, or a content type. Use association forms to capture general parameter settings from the administrator.
Initiation (or instantiation) forms are displayed when a workflow instance starts, either as the result of a manual action by the user or triggered from an event (such as the addition of a document in the library).
Edit task forms are displayed when users are editing tasks assigned to them.
Modification forms are displayed when the predefined path is changed during the workflow.
This how-to discusses the first three types of forms.
Both the association and the initiation form must work with a main data source that is defined within the same namespace.
All forms must be published to a network location with the alternate access path left blank.
The following code examples show how to interact programmatically with the InfoPath 2007 forms that are displayed to the user during the various stages of the workflow life cycle.
Reading the Data from the Association and the Initiation Forms
In the workflow code-behind classes, a variable named workflowProperties of type Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties is created and populated with Office SharePoint Server and workflow contextual data. The InitiationData property is exposed at this level, giving you access to the data entered in both the association and the initiation form. This data is typically processed during the activation of the workflow. The data is made available as an XML string that can be processed through the use of a System.Xml.XmlDocument instance and the execution of XPath statements, as shown in the following code example.
public SPWorkflowActivationProperties workflowProperties =
private void onWorkflowActivated1_Invoked
(object sender, ExternalDataEventArgs e)
XmlDocument doc = new XmlDocument();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
this.manager = doc.SelectSingleNode
this.comments = doc.SelectSingleNode
Reading the Data from the Edit Task Form
Data entered by the users in the edit task form is retrieved through the ExtendedProperties hash table that stores key/value pairs. The following code shows how the value of the TaskStatus field (one that is set when clicking the approve or reject button in the InfoPath form) and the comments entered by the approver in the form are retrieved.
private void onTaskChanged1_Invoked
(object sender, ExternalDataEventArgs e)
string taskstatus =
this.taskDone = ((taskstatus == "Approved") ||
(taskstatus == "Rejected"));
this.workflowProperties.Item["Comments by Approver"] =
taskstatus.ToUpper() + " : " +
A custom workflow built with Microsoft Visual Studio 2005 is compiled into a .NET assembly and deployed in the global assembly cache. The workflow template is made available at the level of the site collection through a Feature. The InfoPath 2007 templates that are part of the workflow are published to a subfolder of the workflow Feature folder. You define this subfolder in the feature.xml file via the Property element, with the Key attribute set to RegisterForms.
Title="Custom Timesheet Approval Feature"
Description="This feature is a workflow that ..."
<ElementManifest Location="workflow.xml" />
<Property Key="GloballyAvailable" Value="true" />
<!-- Value for RegisterForms key indicates the path to
the forms relative to feature file location -->
<!-- if you do not have forms, use *.xsn -->
<Property Key="RegisterForms" Value="Forms\*.xsn" />
In the elementmanifest file (the workflow.xml in the project), each of the Microsoft InfoPath 2007 templates is registered and connected to the proper phase in the workflow lifecycle in the MetaData section of the XML.
<Workflow Name="Custom Timesheet Approval"
Description="This workflow allows users to approve
<!-- Tags to specify InfoPath forms for the workflow; delete
tags for forms that you do not have -->
Watch the Video
Length: 10:00 | Size: 12.2 MB | Type: WMV file