InfoPath forms deployment, SharePoint workflow in VS 2008


A number of developers who have tried the SharePoint workflow features in VS 2008 wanted to know more about our support for InfoPath forms deployment. So I’m blogging it here for everyone’s reference.

Before diving into details of InfoPath forms deployment here’s a little bit of background on workflow and InfoPath forms integration. Typical SharePoint workflows goes through different stages – association, initiation, task completion. Also, workflows might be modified after being initiated. SharePoint supports ASP.NET and InfoPath forms to enable developers to capture user inputs at these different stages. For example, on initiation of a simple document approval workflow you might want to capture the approvers for the document.

To develop InfoPath forms you can either use the VSTO template for InfoPath that also ships with Visual Studio 2008 or InfoPath (with VSTA) itself. Once you have designed the InfoPath form it can be published as an XSN file. There is some great documentation on MSDN regarding this. In general, if you need code (custom event handlers/validation) behind your InfoPath forms you should use the VSTO InfoPath template and create a project alongside your workflow project.

Coming back to SharePoint workflow integration with InfoPath forms – It is very easy to deploy InfoPath forms along with your workflow. All you have to do is to add a relative reference to the form in the feature.xml with the <ElementFile/> element eg:

<ElementFile Location="InfoPathForm.xsn" />

When you press F5 you will see that VS will copy the form alongside your feature.xml files in the 12\TEMPLATE\FEATURES\<featname>\ directory. It must be noted that this is a relative reference to the form and VS will look in the path specified relative to the source location of feature.xml.

You can use the above feature to also install resx files or any other accompanying files. Also, the feature.xml file is processed by SharePoint on feature installation and absolute paths or relative references with ellipsis are not supported (for obvious security reasons). However, you can add references that need to be deployed as subdirectories and we will replicate the hierarchy eg:

<ElementFile Location="InfoPathForms\InfoPathForm1.xsn" />
<ElementFile Location="Resources\Resources.en-us.resx" />

On F5, a subdirectory named InfoPathForms and Resources will be created in the 12\TEMPLATE\Features\<featname>\ directory.

And yeah, don’t forget to reference them also in the workflow.xml as an initiation, association, modification or task form, to see them show up at runtime.

Now go ahead and have fun with InfoPath forms!

Comments (12)

  1. Paul Hickman says:

    How exactly do you reference the xsn file you have uploaded in the workflow.xml. The only documentation I can find on MSDN give an example:

    <Association_FormURN>urn:schemas-microsoft-

       com:office:infopath:workflow:ReviewRouting-Assoc:1033

    </Association_FormURN>

    However, if I try and reference the InfoPath form uploaded to my Feature folder with:

    <Association_FormURN>InfoPathForm.xsn</Association_FormURN>

    I get an error when opening the form "The URL InfoPathForm.xsn is an unsupported relative URL. Use an absolute URL of prefix with ‘~sitecollection’, for a site-collection-relative-url."

    What goes in the <Association_FormURN> tag to point it at the file in the feature folder?

  2. nikhilkh says:

    Hi Paul,

    The URN that you reference in the workflow.xml is the URN of the InfoPath form and not the actual file name.

    You will also notice that, by default, the feature.xml file contains a <Property Key="RegisterForms" Value="*.xsn" /> that registers the InfoPath form with SharePoint server when the feature in installed. At registration time, SharePoint internally creates a mapping of the InfoPath form filename and the URN of the form. Therefore, you do not need to reference the filename itself in the workflow.xml file as long as the form itself has been registered.

    To view the list of registered InfoPath form templates, you can run stsadm -o enumformtemplates.

    Hope this explains why there is no need to reference the filename itself.

    Thanks,

    Nikhil

    N.B.:To find the form URN, open the form in "Design mode" in InfoPath and see the ID property from File->Properties.

  3. Richard Jacobs says:

    Hi,

    Great blog, really easy to follow and makes it so simple!

    I have been trying to go a step further and develop a workflow with my own Association and Initiation forms developed in InfoPath 2007 and published to a network location (my VS2008 project).

    When I run the workflow and create a new document in the document library I get an error on my “onWorkflowActivated” method. “workflowProperties.InitiationData” is null. I believe this is because my initiation form is not opened. Is there any reason why my initiation form is not opened? I have changed the URNs in the workflow.xml file. I also tried using the elementfile location tag in the feature.xml file, but still got the same error.

    Any ideas?

    Thanks in advance

  4. nikhilkh says:

    Hi Richard,

    Thanks for the comments!

    Do you see the initiation form when you start the workflow? How are you starting the workflow? I think if you upload a document to start the workflow, the initiation form might not be shown and therefore, Initiation data might be null.

    Thanks,

    Nikhil

  5. One thing you need to clarify about using InfoPath 2007 forms with a workflow is where you store the files for source control vs. where you "Publish" the forms too (locally) vs. where the "published" form gets deployed (…FEATURE…) when using the VS 2008 Deploy menu item.  

    In VS 2005, I stored the ‘unpublished’ .XSN files in one location and then used InfoPath 2007’s "Publish to network location" (which was really just another directory in the VS 2005 project directory for my Solution).  Then VSeWSS 1.1 took it from there in terms of putting the .XSN file out to the proper directory in SharePoint (…FEATURE…).  

    I guess I’m looking for a best practices recommendation in terms of where the "base" XSN is kept vs. where the "locally published" XSN is kept vs. how the "locally published" XSN ends up in the proper directory for use by SharePoint via VS 2008’s new Deploy capability.

  6. Justin Robinson says:

    When you place the urn into the <associationData> tags, do you also need to place something in the associationURL field.  And if so, what would you place there?

    Thanks,

    Justin

  7. elyes85 says:

    Hello, Thanks for your intersting blog !

    I have a problem with deploying InfoPath Forms without VS Template

    I setup all the required file as in VS and I used a batch file to install and setup the feature and nevertheless when the Workflow is initiated It declare InfoPath error ! Form is not located ???

    So I wanna the required action to deploy InfoPath Forms with Wokflow enabled without VSTO ?? Can you help me ??

  8. Senthil says:

    Here is the way How you can deploy the InfoPath form in to SharePoint.

    -Senthil

  9. hi,

    i am using vs2008. it creates a .dll. How to deploy the dll to a  SharePoint Site. i mean safe controls, dll copy in GAC, activate feature etc.

  10. Per Høyer says:

    4 those of you who wanna know about the  Instantiation_FormURN and the Association_FormURN

    You have to till in the values wich will look something like this:

    <Instantiation_FormURN>urn:schemas-microsoft-com:office:infopath:AssocForm:-myXSD-2009-10-01T17-35-38</Instantiation_FormURN>

    <Association_FormURN>urn:schemas-microsoft-com:office:infopath:AssocForm:-myXSD-2009-10-01T17-35-38</Association_FormURN>

    You get this path by:

    1. In InfoPath open the published form from the loc. to where it was published (the feature folder)

    2. Open the File -> Properties – and there it is.

    One thing thoug – for reasons i dont quite get yet – you will not be able to create different forms for assoc and init – If you do (meaning that you will enter 2 different urns in the 2 tags above – your initform wont load. Why the f… that is i have no idea, but it sure is frustrating

  11. Mehul Bhuva says:

    Hi Nikhil,

    I have attempted to cover this topic in detail

    See my blog post where I take you step-by-step with relevant snapshots covering the following:

    a. Converting InfoPath Data Connections to DCL library in SharePoint.

    b. Publishing InfoPath form to a SharePoint List/Library

    c. Creating a .wsp solution package for the InfoPath form and its code-behind

    d. Creating a batch script that will deploy the InfoPath form on your Production site.

    e. Ensuring the InfoPath form has been deployed as a feature

    f.  Modify the DCL’s in the production environment.

    g. Associate the InfoPath Content Type with the Document/Forms Library

    See the full blog post at: http://www.sharepointfix.com/2009/12/infopath-2007-form-and-nintex-workflows.html