Deploying an InfoPath form to SharePoint 2010 is relatively straight forward, as long as you remember a few simple steps.
For an easier deployment experience, avoid code behind (managed forms) in your InfoPath form unless you really have to. That’s for another day, so this post will concentrate on how to deploying an InfoPath form with no associated code behind files.
Open InfoPath and either open or create a form. I’m not going to go into how to hook up the form with a data connection, just how to configure and publish it.
Once you’re happy with your form, have added any relevant data connections and wired up a submit button, you’ll need to set the trust level to Domain. By default this will be set to Restricted, which is too low for use in SharePoint. If you try to deploy a form with a restricted trust level the form will not be able to:
- use data connections (with the exception of submitting via email)
- run managed code or script
- use custom or ActiveX controls
- Process rules associated with opening the form
To change the security level, click on the File tab in the ribbon and then select Info from the left hand menu (should be auto selected). Click Advanced form options from the list provided. This will load the Form Options dialog. Select the Security and Trust category and change your settings to the Domain security level, as shown in the following screenshot:
To deploy the form from SharePoint you’ll need to publish the form and use the published version within your SharePoint project. Stay on the File tab and select Publish from the left hand menu. From the list of options presented, click Publish form to a network location or file share.
Select a location to publish the form to (you’ll need to make sure that this is the file you include in your SharePoint deployment project) and give it a name. As we’ll be publishing this form to SharePoint and all users will access it from the form templates gallery, make sure the second screen of the Publishing Wizard does not contain a path. SharePoint will then ensure users can access the form, so no need to provide an alternate access URL.
Click next and OK the popup ignoring the warning about users not being able to access the form. Finally, click Publish to create a published version of your form.
From within your SharePoint project, you’ll need to add the published InfoPath form and configure a feature to correctly deploy it. To add the form, create a new module, deleting the Sample.txt file that it automatically creates. Add the published form to this module. Your module’s elements XML file should now look something like the following:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="FormsModule"> <File Path="FormsModule\aform.xsn" Url="PublishedForms/aform.xsn" /> </Module> </Elements>
Next, you need to edit the manifest for the feature that deploys the form module. Open the feature in Visual Studio and click the Manifest link at the bottom of the screen.
From the manifest page, click the Edit Options link, which will bring up an editor window similar to the following:
Change it to contain the following text:
You’ll need to change the value for the key RegisterForms so it points to the name of the module you created earlier. This will register your form(s) when the feature is activated, providing you follow the next set of steps.
From the feature’s main page, bring up the properties window for it and set the following property values:
Receiver Assembly = Microsoft.Office.Workflow.Feature, Version=220.127.116.11, Culture=neutral, PublicKeyToken=71e9bce111e9429c
Receiver Class = Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver
By hooking up the feature to use the WorkflowFeatureRecevier class from the Microsoft.Office.Workflow.Feature assembly, the property values added to the feature manifest will be loaded and processed as it is activated. This ensures that your form is uploaded to the form templates gallery (in SharePoint) and registered correctly.
You should now be able to use the form within your SharePoint instance, for example by using it as an instantiation form for a custom workflow:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Workflow Name="Workflow name" Description="Workflow description" Id="70AE73A8-388D-4E15-AB75-4385BDE528B5" CodeBesideClass="CustomWorkflows.CustomWorkflowClass" CodeBesideAssembly="$assemblyname$" InstantiationUrl="_layouts/IniWrkflIP.aspx"> <Categories/> <MetaData> <AssociationCategories>List</AssociationCategories> <Instantiation_FormURN>urn:schemas-microsoft-com:office:infopath:aform:-myXSD- 2010-11-30T17-05-30</Instantiation_FormURN> <StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl> </MetaData> </Workflow> </Elements>
You can get the URN for your InfoPath form by opening the form in InfoPath in design mode, changing to the File tab and clicking the Form Template Properties button, located to the right of the screen. This will display a dialog which contains a field called ID, the content of which is the value required for the URN in the above XML.