Designing InfoPath Forms for Workflows in SharePoint Server 2007

Summary:  Learn how to design Microsoft Office InfoPath forms for workflows in Microsoft Office SharePoint Server 2007.

Office Visual How To

Applies to:  2007 Microsoft Office System, Microsoft Office SharePoint Server 2007, Microsoft Visual Studio 2005 Extensions for Microsoft .NET Framework 3.0 (Windows Workflow Foundation), SharePoint Server 2007 SDK

Joel Krist, Akona Systems

February 2008

Overview

A workflow enables you to attach a business process to items in Microsoft Office SharePoint Server 2007. This process can control almost any aspect of an item in Office SharePoint Server, including the life cycle of that item. A workflow can be as simple or as complex as business processes require.

You can create workflows for Office SharePoint Server that incorporate Microsoft Office InfoPath 2007 forms technology. This enables users to interact with the workflows by using 2007 Microsoft Office system client applications (such as Microsoft Office Excel 2007, Microsoft Office Word 2007, Microsoft Office PowerPoint 2007, and Office InfoPath), and by using a Web browser.

This Office Visual How To shows you how to design InfoPath forms for workflows in SharePoint Server 2007. The workflow created with this walkthrough is very simple. When activated, it creates a new SharePoint task that is associated with a list item. It then waits for the user to specify the task as completed. After the user specifies that the task is completed, the workflow sets the SharePoint task as completed and then ends. The workflow uses one custom InfoPath form to collect initiation data from the user who started the workflow, and another form to enable the user to edit the workflow task and mark the task as complete.

The following software is required to follow the steps described in this article:

  • Microsoft Visual Studio 2005, with Visual Studio 2005 Extensions for Microsoft .NET Framework 3.0 (Windows Workflow Foundation)

  • Microsoft Office SharePoint Server 2007

  • Microsoft Office InfoPath 2007

  • The Enterprise Content Management (ECM) Starter Kit, which contains a Visual Studio project template for SharePoint workflows and instructions for installing the template. The ECM Starter Kit is included in the Microsoft Office SharePoint Server 2007 SDK, available from the Microsoft Download Center.

Note

As with all Office SharePoint Server 2007 development, it is strongly recommended that you develop workflows on the server where they will be installed. This simplifies the development and debugging process. The workflow activities that are specific to Office SharePoint Server 2007 require that Windows SharePoint Services and Office SharePoint Server 2007 are installed on the computer that you use to develop the workflows.

See It Designing InfoPath Forms for Workflows

Watch the Video

Length: 15:19 | Size: 12.9 MB | Type: WMV file

Code It | Read It | Explore It

Code It

To demonstrate how to design Office InfoPath forms for workflows in SharePoint Server 2007, this section walks through eight important steps:

  1. Creating the workflow initiation form.

  2. Creating the workflow task edit form.

  3. Creating a SharePoint Sequential Workflow Library project in Visual Studio.

  4. Adding code to respond to workflow activation.

  5. Designing the workflow by using Microsoft Visual Studio 2005 Designer for Windows Workflow Foundation.

  6. Setting the properties of the workflow activities.

  7. Signing the workflow library assembly with a strong name.

  8. Deploying the workflow.

Creating the Workflow Initiation Form

The workflow initiation form is displayed to the user when the workflow is first activated. To create the workflow initiation InfoPath form, do the following:

  1. Open Office InfoPath 2007. In the Getting Started dialog box, click Design a Form Template.

  2. In the Design a Form Template dialog box, click Blank, select the Enable browser-compatible features only check box, and then click OK.

  3. In the Design Tasks pane, click Controls.

  4. On the form, add the following controls:

    1. Type Assign Task To:, press Enter, and then drag a text box control onto the form from the Controls pane. Right-click the text box control, and then click Text Box Properties. For Field name, type assignee. Click Apply. On the Size tab, set the width to 300 px, and then click OK.

    2. On the form, press the right-arrow key once, and then press Enter twice. Type Instructions:, press Enter, and then drag another text box control onto the form. Right-click the text box control, and then click Text Box Properties. For Field name, type instructions. Click Apply. On the Size tab, set the width to 300 px, and then click OK.

    3. On the form, press the right-arrow key once, and then press Enter twice. Type Comments:, press Enter, and then drag another text box control onto the form. Right-click the text box control, and then click Text Box Properties. For Field name, type comments. Click Apply. On the Size tab, set the width to 300 px, and then click OK.

    4. On the form, press the right-arrow key once, and then press Enter twice. Drag a button control onto the form from the Controls pane. Right-click the button control, and then click Button Properties. On the General tab, for Label, type Submit, and then click OK.

    The form should look like Figure 1.

    Figure 1. Workflow initiation form

    Workflow initiation form

    Note

    The text fields are named assignee, instructions, and comments. You reference these fields by these names in the section of this article titled "Adding Code to Respond to Workflow Activation," when you add code to the workflow to work with the initiation form data.

  5. Give the form fields collection a unique name:

    1. In the Design Tasks pane, click Data Source.

    2. In the Data Source pane, right-click MyFields, and then click Properties.

    3. In the Field or Group Properties dialog box, for Name, type InitForm.

    4. Click OK to save the change.

    Later in this article, you extract the schema (.xsd) file for this form and use it as the basis for the class referenced in the workflow code that processes the initiation form data. The root element of the schema file is named the same as the form fields collection. The class generated from the schema file has the same name as the schema file root element.

    Specifying a unique name for the fields collection, rather than using the default name of myFields, helps ensure that the class that is generated from the form schema file also has a unique name. This is especially important when programming a workflow that deserializes multiple forms.

  6. Add rules to the Submit button:

    Note

    One rule submits the form information to the hosting environment (in this case, Office SharePoint Server); the other rule closes the form when the user clicks Submit.

    1. Right-click the Submit button control on the form, and then click Button Properties.

    2. In the Button Properties dialog box, on the General tab, click Rules.

    3. In the Rules dialog box, click Add.

    4. In the Rule dialog box, click Add Action. In the Action drop-down list, select Submit using a data connection, and then click Add.

    5. In the Data Connection Wizard, click Create a new connection to and Submit data, and then click Next.

    6. Under How do you want to submit your data, click To the hosting environment, and then click Next. Click Finish.

    7. Click OK to close the Action dialog box.

    8. Click OK to close the Rule dialog box.

    9. In the Rules dialog box, click Add.

    10. In the Rule dialog box, click Add Action.

    11. In the Action drop-down list, select Close the form, and then click OK.

    12. Click OK to close the Rule dialog box.

    13. Click OK to close the Rules dialog box.

    14. Click OK to close the Button Properties dialog box.

  7. Set the security level of the form to Domain:

    1. On the Tools menu, click Form Options.

    2. In the Form Options dialog box, in the Category list, click Security and Trust.

    3. Under Security Level, clear the Automatically determine security level check box, and then click Domain.

    4. Click OK to save the changes and close the Form Options dialog box.

  8. Publish the form:

    1. On the File menu, click Save As. In the Save As dialog box, for File name, type InitForm.xsn. Save the form to any location.

    2. On the File menu, click Publish.

    3. In the Publishing Wizard, select To a network location, and then click Next.

    4. Click Browse. In the Browse dialog box, navigate to the folder where you want to publish the form. For File name, type InitForm, and then click OK.

    5. In the Publishing Wizard, for Form template name type InitForm, and then click Next.

    6. Clear the alternate path to the form from the text box, and then click Next.

      Note

      Do not specify an alternate path to the form. If you specify an alternate path, it causes an error that prevents publishing the form to the server.

    7. Click Publish, and then click Close.

  9. Determine the ID of the InitForm form:

    1. On the File menu, click Properties.

      Figure 2. Form Template Properties dialog box

      Form Template Properties dialog box

    2. In the Form Template Properties dialog box, note the ID. You will use the form ID when you deploy the workflow.

    3. Click Cancel to close the Form Template Properties dialog box.

  10. Generate a new class file, based on the form schema (.xsd) file:

    1. On the File menu, click Save As Source Files. Browse to the location where you want to save the form source files, and then click OK.

      InfoPath saves a collection of form source files, including the schema file, to the specified location. The form schema file is always named myschema.xsd.

    2. On the File menu, click Close to close the form in InfoPath.

      Next, you use the Microsoft .NET Framework 2.0 command-line tool, xsd.exe, to generate a new class file from the form schema.

    3. In Visual Studio 2005, open a Visual Studio Command window, navigate to the location of the myschema.xsd file, and then run the following command:

      xsd myschema.xsd /c /l:language
      

      Replace language with either VB or CS, depending which language you will write the workflow in. This command generates a new class file based on the form schema. The file is named the same as the schema file, that is, myschema.cs or myschema.vb, and is located in the current directory. The class in the file is named the same as the root element of the schema, which was named the same as the form fields collection.

      Note

      If the form is still open in InfoPath, xsd returns an error stating that it cannot access the file because it is being used by another process.

  11. Rename the myschema.cs or myschema.vb file to InitForm.cs or InitForm.vb.

Creating the Workflow Task Edit Form

  1. Open Office InfoPath 2007. In the Getting Started dialog box, click Design a Form Template.

  2. In the Design a Form Template dialog box, click Blank, select the Enable browser-compatible features only check box, and then click OK.

  3. In the Design Tasks pane, click Controls.

  4. Add controls:

    1. On the form, type Comments:, press Enter, and then drag a text box control onto the form from the Controls pane. Right-click the text box control, and then click Text Box Properties. For Field name, type comments. Click Apply. On the Size tab, set the width to 300 px, and then click OK.

    2. On the form, press the right-arrow key once, and then press Enter twice. Drag a check box control onto the form. Right-click the check box control, and then click Check Box Properties. For Field name, type isFinished, and then click OK.

    3. Next to the check box, select the text Field 2. Type Complete Task, to replace the text Field 2. Press Enter twice.

    4. Drag a button control onto the form. Right-click the button control, and then click Button Properties. On the General tab, for Label, type OK. Click Apply. On the Size tab, set the width to 80 px, and then click OK.

    The form should look like Figure 3.

    Figure 3. Workflow task edit form

    Workflow task edit form

  5. Add the same rules to the OK button as you previously added to the Submit button of the initiation form. (See Step 6 of the section Creating the Workflow Initiation Form.)

  6. Create a schema file for the workflow task schema:

    1. In a text editor, such as Notepad, create a file named ItemMetadata.xml.

      Note

      The file name is case-sensitive.

    2. Add the following markup to the ItemMetadata.xml file.

      <z:row xmlns:z="#RowsetSchema" 
        ows_comments="" 
      />
      
    3. Save the ItemMetadata.xml file.

  7. Add the workflow task schema to the task edit form as a secondary data source:

    1. In Office InfoPath 2007, on the Design Tasks pane, select Data Source, and then click Manage Data Connections.

    2. In the Data Connections dialog box, click Add.

    3. In the Data Connection Wizard, click Create a new connection to and Receive data, and then click Next.

    4. Click XML document, and then click Next.

    5. Click Browse, navigate to the folder where you saved ItemMetadata.xml, select it, and then click Open. Click Next.

    6. Click Include the data as a resource file in the form template or template part, and then click Next.

    7. Type ItemMetadata as the data connection name, and ensure that the Automatically retrieve data when form is opened check box is selected. Click Finish. Click Close.

      After you include the ItemMetadata.xml file as a resource file in the form template, the file is no longer needed in the workflow solution.

      Note

      ItemMetadata.xml is required as a secondary data source for task forms. If you do not add ItemMetadata.xml as a secondary data source, the form generates an error upon opening.

  8. Data-bind the Comments text box control to the comments elements in the workflow task schema:

    1. On the form, right-click the text box control, and then click Text Box Properties.

    2. In the Text Box Properties dialog box, on the Data tab, in the Default Value section, click the formula button.

    3. In the Insert Formula dialog box, click Insert Field or Group.

    4. In the Select a Field or Group dialog box, in the Data source list, select ItemMetadata.

    5. Click the ows_comments element, and then click OK.

    6. In the Insert Formula dialog box, click OK.

    7. In the Text Box Properties dialog box, click OK.

    The Comments text box control is now bound to the comments workflow task property. When Office SharePoint Server 2007 loads the task form, the form displays the task comments in the text box.

  9. Set the security level of the form to Domain:

    1. On the Tools menu, click Form Options.

    2. In the Form Options dialog box, in the Category list, click Security and Trust.

    3. Under Security Level, clear the Automatically determine security level check box, and then click Domain.

    4. Click OK to save the changes and close the Form Options dialog box.

  10. Publish the form:

    1. On the File menu, click Save As. In the Save As dialog box, for File name, type TaskForm.xsn. Save the form to any location.

    2. On the File menu, click Publish.

    3. In the Publishing Wizard, select To a network location, and then click Next.

    4. Click Browse. In the Browse dialog box, navigate to the folder where you want to publish the form. For File name, type TaskForm, and then click OK.

    5. In the Publishing Wizard, for Form template name type TaskForm, and then click Next.

    6. Clear the alternate path to the form from the text box, and then click Next.

      Note

      Do not specify an alternate path to the form. If you specify an alternate path, it causes an error that prevents publishing the form to the server.

    7. Click Publish, and then click Close.

  11. Determine the ID of the TaskForm form:

    1. On the File menu, click Properties.

      Figure 4. TaskForm form template properties

      TaskForm form template properties

    2. In the Form Template Properties dialog box, note the ID. You will use the form ID when you deploy the workflow.

    3. Click Cancel to close the Form Template Properties dialog box.

Creating a SharePoint Sequential Workflow Library Project in Visual Studio 2005

To create a SharePoint Sequential Workflow Library project in Visual Studio 2005:

  1. Start Visual Studio.

  2. On the File menu, click New, and then click Project.

  3. In the New Project dialog box, in the Project types pane, select Visual C# or Visual Basic for the project type, and then click SharePoint.

  4. In the Templates pane, click Sequential Workflow Library. Type InfoPathFormWorkflowLibrary as the project Name, specify a Location for the project, and then click OK.

    Visual Studio creates a new solution containing the workflow library project.

    Figure 5. Creating a SharePoint Sequential Workflow Library Project

    SharePoint Sequential Workflow Library Project

  5. Add the InitForm.cs or InitForm.vb class file that you created previously for the initiation form schema to the InfoPathFormWorkflowLibrary project:

    1. In Solution Explorer, right-click the InfoPathFormWorkflowLibrary project, click Add, and then click Existing Item.

    2. In the Add Existing Item dialog box, navigate to the folder that contains the InitForm.cs or InitForm.vb file that you created previously, select the file, and then click Add.

      The class file is added to the project.

  6. Add the InitForm.xsn and TaskForm.xsn files that you created previously (when you published the initiation and task edit forms) to the InfoPathFormWorkflowLibrary project:

    1. In Solution Explorer, right-click the InfoPathFormWorkflowLibrary project, click Add, and then click Existing Item.

    2. In the Add Existing Item dialog box, navigate to the folder that contains the InitForm.xsn and TaskForm.xsn files that you created previously, select the files, and then click Add.

      The form template files are added to the project.

Adding Code to Respond to Workflow Activation

To display the workflow outline:

  • In Solution Explorer, expand the InfoPathFormWorkflowLibrary project node, and then double-click the Workflow1.cs file.

The initial workflow outline is displayed in the Workflow Designer, showing the OnWorkflowActivated activity added by Visual Studio.

Figure 6. Initial workflow outline

Initial workflow outline

The OnWorkflowActivated activity runs when the workflow is first activated. It is a good place to process the information specified by the user via the workflow initiation form.

To add a method that is called when the OnWorkflowActivated activity is run, set the Invoked property of the onWorkflowActivated1 activity:

  1. Right-click the onWorkflowActivated1 activity, and then click Properties.

  2. In the Properties pane, type onWorkflowActivated as the value of the Invoked property, and then press Enter.

    Visual Studio opens the Workflow1.cs or Workflow1.vb file in the code editor with the generated onWorkflowActivated method visible.

  3. In the Workflow1.cs or Workflow1.vb file, add the following Imports or using statements below the Imports or using statements generated by Visual Studio.

    Imports System.Xml
    Imports Microsoft.SharePoint.Workflow
    
    using Microsoft.SharePoint.Workflow;
    
  4. Add the following string variable declarations to the Workflow1 class.

    Private assignee As String = String.Empty
    Private instructions As String = String.Empty
    Private comments As String = String.Empty
    Private isFinished As Boolean = False
    Public workflowId As Guid
    
    private String assignee = default(String);
    private String instructions = default(String);
    private String comments = default(String);
    private bool isFinished = false;
    
  5. Add the following code to the onWorkflowActivated method to parse the incoming workflow initiation data.

    workflowId = workflowProperties.WorkflowId
    
    Dim serializer As XmlSerializer = New XmlSerializer(GetType(InitForm))
    Dim reader As XmlTextReader = New XmlTextReader( _
        New System.IO.StringReader(workflowProperties.InitiationData))
    Dim initform As InitForm = _
        CType(serializer.Deserialize(reader), InitForm)
    
    assignee = InitForm.assignee
    instructions = InitForm.instructions
    comments = InitForm.comments
    
    workflowId = workflowProperties.WorkflowId;
    
    XmlSerializer serializer = new XmlSerializer(typeof(InitForm));
    XmlTextReader reader = new XmlTextReader(
        new System.IO.StringReader(workflowProperties.InitiationData));
    InitForm initform = (InitForm)serializer.Deserialize(reader);
    
    assignee = initform.assignee;
    instructions = initform.instructions;
    comments = initform.comments;
    

Designing the Workflow

To design the outline of the workflow:

  1. Switch to the workflow designer window.

  2. Open the Visual Studio toolbox.

  3. Drag a CreateTask activity, a WhileActivity activity, and a CompleteTask activity, in that order, to the workflow outline.

  4. Drag an OnTaskChanged activity inside the whileActivity1 activity.

    Figure 7. Final workflow outline

    Final workflow outline

    Note

    If the SharePoint workflow activities are not visible in the Visual Studio toolbox, you can load them: In workflow design mode, right-click the Toolbox, and then click Choose Items. On the Activities tab, browse to the %programfiles%/Common Files/Microsoft Shared/web server extensions/12/ISAPI folder, and select the Microsoft.SharePoint.WorkflowActions.dll file, and then click OK.

Setting Workflow Activity Properties

The Workflow Designer displays red exclamation marks next to each of the workflow activities that you added in the previous step. For the task-related activities, this is because you have not set their correlation token property yet. A correlation token is a unique identifier that enables mapping between the objects in a workflow and the environment hosting the Windows Workflow Foundation (WF) workflow runtime.

To set the properties for the task-related activities:

  1. Right-click the Workflow Designer surface, and then click View Code to open the workflow code file .

    The Workflow1.cs or Workflow1.vb file is displayed in the code editor.

  2. In the Workflow1.cs or Workflow1.vb file, add the following lines of code to the body of the Workflow1 class, just below the line that Visual Studio generated that defines the workflowProperties variable.

    Public taskId As Guid = Guid.Empty
    Public taskProperties As SPWorkflowTaskProperties = _
        New SPWorkflowTaskProperties()
    
    public Guid taskId = default(System.Guid);
    public SPWorkflowTaskProperties taskProperties =
        new SPWorkflowTaskProperties();
    
  3. Switch to the workflow design view, right-click the createTask1 activity, and then click Properties.

  4. In the Properties pane, type taskToken as the value of the CorrelationToken property, and then press Enter.

    A plus sign is displayed to the left of the CorrelationToken property.

  5. Click the plus sign to display the OwnerActivityName property. Set its value by expanding the property value dropdown list and clicking Workflow1.

  6. Click the TaskId property, and then click the ellipses (…) button.

  7. In the Property Bind dialog box, click the taskId property that you created in Step 2, and then click OK.

    Figure 8. Binding the TaskId property

    Binding the TaskId property

  8. Click the TaskProperties property, and then click the ellipses (….) button.

  9. In the Property Bind dialog box, click the taskProperties property that you created in Step 2, and then click OK.

    Figure 9. Binding the TaskProperties property

    Binding the TaskProperties property

  10. Right-click the onTaskChanged1 activity, and then click Properties.

  11. In the Properties pane, click the CorrelationToken property. Set its value by expanding the property value dropdown list and clicking taskToken.

  12. Click the TaskId property, and then click the ellipses (….) button.

  13. In the Bind dialog box, click the taskId property that you created in Step 2, and then click OK.

  14. Click the AfterProperties property, and then click the ellipses (….) button.

  15. In the Property Bind dialog box, click the taskProperties property that you created in Step 2, and then click OK.

  16. Right-click the completeTask1 activity, and then click Properties.

  17. In the Properties pane, click the CorrelationToken property. Set its value by expanding the property value dropdown list and clicking taskToken.

  18. Click the TaskId property, and then click the ellipses (….) button.

  19. In the Property Bind dialog box, click the taskId property that you created in Step 2, and then click OK.

At this point, the taskId variable used for the TaskId property of the task-related activities has a default GUID value of all zeros. The title property of the taskProperties variable is not set. To initialize these variables, do the following:

  1. In the workflow designer, double-click the createTask1 activity.

    Visual Studio switches to the Workflow1.cs or Workflow1.vb file and displays the body of the createTask1_MethodInvoking method. This method is called prior to the createTask1 activity being started.

  2. Add the following code to the body of the createTask1_MethodInvoking method.

    taskId = Guid.NewGuid()
    taskProperties.Title = "Task for " + workflowProperties.Item.Name
    taskProperties.Description =
        "A task from the InfoPath forms workflow."
    taskProperties.ExtendedProperties("Assignee") = assignee
    taskProperties.ExtendedProperties("Comments") = comments
    taskProperties.ExtendedProperties("Instructions") = instructions
    
    taskId = Guid.NewGuid();
    taskProperties.Title = "Task for " + workflowProperties.Item.Name;
    taskProperties.Description =
        "A task from the InfoPath forms workflow.";
    taskProperties.ExtendedProperties["Assignee"] = assignee;
    taskProperties.ExtendedProperties["Comments"] = comments;
    taskProperties.ExtendedProperties["Instructions"] = instructions;
    

    The next step is to set the properties of the While activity. The While activity causes the activities inside it to loop as long as the condition it evaluates resolves to true. In this example, it is used to loop around the TaskChanged activity until the user explicitly completes the task.

  3. To set the properties of the While activity:

    1. Switch to the workflow design view, right-click the whileActivity1 activity, and then click Properties.

    2. In the Properties pane, type Code Condition as the value of the Condition property.

      This tells the While activity that it is calling a method to determine to end the loop. A plus sign is displayed to the left of the Condition property.

    3. Click the plus sign, type notFinished as the value of the Condition subproperty, and then press Enter.

      Visual Studio switches back to code view and displays the code for the generated notFinished method.

  4. Add the following code to the notFinished method:

    e.Result = Not isFinished
    
    e.Result = !isFinished;
    

    This code checks the value of the isFinished variable. The value of the isFinished variable is set depending on whether the user checked the Complete Task check box on the workflow task edit form. To set the value of the isFinished variable, add a method that is called when the TaskChanged activity is run:

  5. Switch to the workflow design view, right-click the onTaskChanged1 activity, and then click Properties.

  6. In the Properties pane, type onTaskChanged as the value of the Invoked property, and then press Enter.

    Visual Studio switches to code view and displays the code for the generated onTaskChanged method.

  7. Add the following code to the onTaskChanged method:

    isFinished = Boolean.Parse( _
        taskProperties.ExtendedProperties("isFinished").ToString())
    
    isFinished = bool.Parse(
        taskProperties.ExtendedProperties["isFinished"].ToString());
    

Each time the user edits the task, the onTaskChanged1 activity handles the task changed event. It invokes the onTaskChanged method, which examines the task properties and sets the isFinished variable to represent whether the user marked the task as complete. The while1 activity then invokes the notFinished method, which sets the result of the event to the opposite of the isFinished variable. If isFinished is equal to false, the event result is set to true, and the while1 activity waits for task changes. If isFinished is equal to true, the event result is set to false, the while1 activity completes, and the workflow continues to the next activity. The next activity is the CompleteTask activity, which sets the task as complete.

Signing the Workflow Library Assembly with a Strong Name

For the workflow library assembly to be installed in the Global Assembly Cache, it must be signed with a strong name. A strong name consists of the assembly's identity—its simple text name, version number, and culture information (if provided)—plus a public key and a digital signature. To assign a strong name to the assembly in Visual Studio:

  1. On the Project menu, click Properties, and then click ProjectName.

  2. On the Project Properties page, on the Signing tab, select the Sign the assembly check box.

  3. In the Choose a strong name key file list, click New.

  4. In the Create Strong Name Key dialog box, type Keyfile as the key file name, and then clear the Protect my key file with a password check box.

  5. Close the Project Properties page.

  6. Build the workflow library.

Deploying the Workflow

When Visual Studio created the InfoPathFormWorkflowLibrary project, it created two deployment-related files: Feature.xml and Workflow.xml. Feature.xml defines the workflow as an installable SharePoint feature. Workflow.xml defines the actual workflow. Initially, these files contain only instructions for how to insert the necessary code to define the workflow feature and the workflow. To modify the Feature.xml and Workflow.xml files to work with the InfoPathFormWorkflowLibrary workflow:

  1. Open the Feature.xml file and replace its contents with the following markup.

    <?xml version="1.0" encoding="utf-8"?>
    <!-- _lcid="1033" _version="12.0.3111" _dal="1" -->
    <!-- _LocalBinding -->
    
    <Feature  Id="GUID"
              Title="InfoPath Form Workflow"
              Description="This feature is a workflow that demonstrates using InfoPath forms."
              Version="12.0.0.0"
              Scope="Site"
              ReceiverAssembly="Microsoft.Office.Workflow.Feature, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
              ReceiverClass="Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver"
              xmlns="https://schemas.microsoft.com/sharepoint/">
    
      <ElementManifests>
        <ElementManifest Location="workflow.xml" />
      </ElementManifests>
    
      <Properties>
        <Property Key="GloballyAvailable" Value="true" />
        <!-- Value for RegisterForms key indicates the path to the
        forms relative to the feature file location -->
        <Property Key="RegisterForms" Value="Forms\*.xsn" />
      </Properties>
    </Feature>
    
  2. Replace the GUID placeholder text in the <Feature Id> attribute with a unique GUID. You can generate a unique GUID from within Visual Studio:

    1. On the Tools menu, click Create GUID to launch the Create GUID tool.

    2. In the Create GUID tool, click Registry Format, and then click Copy to copy the GUID to the Clipboard.

    3. Paste the GUID into the markup, replacing the GUID placeholder text. Do not include the opening and closing curly braces.

    Figure 10. Creating a GUID

    Creating a GUID

  3. Open the Workflow.xml file and replace its contents with the following markup.

    <?xml version="1.0" encoding="utf-8" ?>
    <!-- _lcid="1033" _version="12.0.3015" _dal="1"   -->
    <!-- _LocalBinding   -->
    
    <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
      <Workflow
           Name="InfoPath Form Workflow"
           Description="This workflow demonstrates using InfoPath forms."
           Id="GUID"
           CodeBesideClass="InfoPathFormWorkflowLibrary.Workflow1" 
           CodeBesideAssembly="InfoPathFormWorkflowLibrary,
           Version=1.0.0.0, Culture=neutral, PublicKeyToken=publicKeyToken"
           InstantiationUrl="_layouts/IniWrkflIP.aspx"
           ModificationUrl="_layouts/ModWrkflIP.aspx"
           StatusUrl="_layouts/WrkStat.aspx"
    TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160" >
    
        <Categories/>
        <MetaData>
          <Instantiation_FormURN>
            InitFormID
          </Instantiation_FormURN>
          <Task0_FormURN>
            TaskFormID
          </Task0_FormURN>
        </MetaData>
      </Workflow>
    </Elements>
    
    1. Use the process described in Step 2 of the section "Deploying the Workflow" to replace the GUID placeholder text in the <Workflow Id> attribute with a unique GUID.

    2. Use the Strong Name (sn.exe) tool that is included with Visual Studio to determine the public key token of the InfoPathFormWorkflowLibrary assembly. Open a Visual Studio Command Window and navigate to the folder that contains the assembly. Run sn.exe with the -T option against the assembly, like this:

      sn.exe -T InfoPathFormWorkflowLibrary.dll
      
    3. Notice the returned public key token and then replace the publicKeyToken placeholder text used with the CodeBesideAssembly attribute with the token returned by sn.exe.

    4. Replace the InitFormID and TaskFormID placeholders used with the Instantiation_FormURN and Task0_FormURN MetaData nodes with the InitForm and TaskForm form IDs determined previously from within InfoPath.

    5. Save the changes to the Feature.xml and Workflow.xml files.

  4. Edit the contents of the Install.bat file, replacing the text generated by Visual Studio with the following:

    echo Copying the feature...
    
    rd /s /q "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\InfoPathFormWorkflowLibrary"
    mkdir "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\InfoPathFormWorkflowLibrary"
    mkdir "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\InfoPathFormWorkflowLibrary\Forms"
    
    copy /Y feature.xml  "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\InfoPathFormWorkflowLibrary\"
    copy /Y workflow.xml "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\InfoPathFormWorkflowLibrary\"
    xcopy /s /Y *.xsn "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\InfoPathFormWorkflowLibrary\Forms"
    
    echo Adding assemblies to the GAC...
    
    "%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf InfoPathFormWorkflowLibrary
    "%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\InfoPathFormWorkflowLibrary.dll
    
    :: Note: 64-bit alternative to lines above; uncomment these to install on a 64-bit computer
    ::"%programfiles% (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf InfoPathFormWorkflowLibrary
    ::"%programfiles% (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\InfoPathFormWorkflowLibrary.dll
    
    echo Activating the feature...
    
    pushd %programfiles%\common files\microsoft shared\web server extensions\12\bin
    
    ::Note: Uncomment these lines if you've modified your deployment xml files or IP forms 
    stsadm -o deactivatefeature -filename InfoPathFormWorkflowLibrary \feature.xml -url https://localhost
    stsadm -o uninstallfeature -filename InfoPathFormWorkflowLibrary \feature.xml
    
    stsadm -o installfeature -filename InfoPathFormWorkflowLibrary \feature.xml -force
    stsadm -o activatefeature -filename InfoPathFormWorkflowLibrary \feature.xml -url https://localhost
    
    echo Doing an iisreset...
    popd
    iisreset
    
    1. Replace the localhost URL used with the stsadm command with the URL of the SharePoint site collection being deployed to.

    2. When deploying a release mode build of the workflow, change the build folder in the path used with the gacutil.exe -if command from Debug to Release.

Build the InfoPathFormWorkflowLibrary project and then run the Install.bat file to deploy the workflow. After the deployment succeeds, you can associate the workflow with a SharePoint list, library, or content type and then test it. For more information about how to associate a workflow with a list, library, or content type, refer to the Add or Change a Workflow for a List, Library, or Content type on Microsoft Office Online.

Read It

This article shows how to design InfoPath forms for workflows in Office SharePoint Server 2007. The steps are:

  1. Creating the workflow initiation form.

  2. Creating the workflow task edit form.

  3. Creating a SharePoint Sequential Workflow Library project in Visual Studio.

  4. Adding code to respond to workflow activation.

  5. Designing the workflow by using Visual Studio 2005 Designer for Windows Workflow Foundation.

  6. Setting the properties of the workflow activities.

  7. Signing the workflow library assembly with a strong name.

  8. Deploying the workflow.

Explore It