SharePoint 2010 Workflow with InfoPath Association Form

Visual Studio 2010 provides a very useful method to help us to package the SharePoint 2010 artifacts and features as package and allow us to hit F5 to debug our code. All is well but sometimes you felt you do not have full control over how the feature is attributed and how the package is assembled.

I created a workflow with association form and I could not get the InfoPath form registered and it took quite a while for me to figure it out so I’d like to share some points here so this might benefit someone who is struggling with the same issue.

Step 1. Create a InfoPath form to be used as association form

  • Make it browser enabled form
  • Make the data connection submit to Host
  • Publish the form to a file folder
  • Write down the InfoPath form ID (File->Form Template Properties), something looks like urn:schemas-microsoft-com:office:infopath:MetadataUpdateInstruction:-myXSD-2010-05-26T20-35-57
  • Export the InfoPath form (Publish –> Export Source Files) to a folder, run xsd.exe against the myschema.xsd to generate a C# or VB class file

Step 2. Create your workflow project

  • Choose workflow project template
  • Make necessary changes to the name of the workflow and feature
  • Make sure it can be compiled and deployed

Step 3. Add InfoPath form into project

  • Add a module to the project named as Forms
  • Add the published InfoPath form into this module
  • In your feature design surface, make sure all artifacts you needed in included in the feature
  • Click on the Manifest, click on Edit Options, add <Property Key=”RegisterForms” Value=”Forms\*.xsn” />
  • In workflow Elements.xml, add AssociationUrl=”_layouts/CstWrkflIP.aspx” attribute to workflow node, uncomment the <Association_FormURN></Association_FormURN> line and add the InfoPath form ID in between
  • Make sure the feature receiver is specified – without this the InfoPath form never got registered
  • And you should see something similar to the following image:

image

Step 4. Reading Association form data inside code

  • The submitted InfoPath form is serialized as string and you can get it from workflowProperties.AssociationData property
  • Add the generated C# code file generated in step 1 to project
  • The following code snippet can be used to get your association data xml

image