Deploy InfoPath 2010 with Code as Solution-Feature
November 22, 2013
Posted by on
This one will be somewhat long of a post. Here we will examine deploying an InfoPath 2010 form with CodeBehind as a custom Feature to SharePoint 2010.
- Change the properties of your form to Full Trust
- Publish your form to a SharePoint Server
Publish Step 1
- Choose your URL to the site where you’re going to be using the file. Note that it will put this form in the Form Templates (url is FormServerTemplates) library at the top of your Site Collection
Publish Step 2
- Make sure that it is checked off to enable the form to be filled out by a browser, and choose Administrator Approved Template
Publish Step 3
- Choose the location on your desktop or local computer or shared drive where you want to save the Published form template to
Publish Step 4
- Create your Visual Studio solution. Create it as a SharePoint 2010 Empty SharePoint Project
Create new Empty SP Project
- Choose to deploy as Farm Solution
Deploy as Farm Solution
- Add a Feature to the project
- Rename the feature to something that makes more sense, so you can more easily find it later through PowerShell or in the 14 hive
- Open the feature in Visual Studio into Design view and set the properties of the feature at the top.
Set Properties of Feature
- Add a Module to the project
- Rename the module and remove the Sample.txt file
Rename Module and remove Sample txt
- Add your Module Files. Here you will be adding the published form that you completed in Step 5 here, as well as the dll. (You can get the .dll by going into design view in InfoPath, pressing Publish, and pressing Export Source Files – give it a folder to put the source files in, and find your .dll in there)
Note that I have a little naming change here versus what I have in step 5. I am showing you a “real” project file and had to blot out part of the name. But this will be your published file – not the file you use to make the changes to the form.
Add Module Files
- Open the Elements file in the NewFormModule. You will have to make changes. Here’s the file as it looks before:
and here’s the file as it looks after:
- Open back up the Feature in Design mode, and press the button to switch it to Manifest mode. Expand Edit Options and add the 2 properties shown below, with your Feature Name and your Published InfoPath form name as the values:
Update the Manifest
- Get the Properties window up for the Feature. You will be adding a Receiver Assembly and a Receiver Class
ReceiverAssembly=”Microsoft.Office.InfoPath.Server, Version=18.104.22.168, Culture=neutral, PublicKeyToken=71e9bce111e9429c”
Feature Props add Receiver info
- OPTIONAL: Add Activation dependency. NOTE: if you are going to mark your feature as Hidden=TRUE, you cannot add this dependency. We will discuss later why you may want to make your feature Hidden.
Feature Activation Dependencies
- Now in your solution explorer, you will want to highlight the Elements file and get the properties. Clear out the Deployment Path and make sure it’s of type ElementManifest
- Next highlight the XSN published form and get its properties. Clear the Deployment Path and make sure it is of type ElementFile
- Repeat the previous step for the DLL file
- Open up your Feature in Design mode just to look at it. Your Manifest file should look similar to the following (if you added the Activation Dependency):
Making the feature Hidden
The problem with adding the published file to Central Administration – Managed Form Templates is twofold: (1) It puts in every version you create into the manifest; and (2) It makes the feature available to EVERY site collection in your Farm. Similarly, if you don’t make the feature Hidden, all site collections will be able to see this feature.
Depending on your project, you may opt to hide the feature so that no one can turn it on, and only activate it to the Site Collection using PowerShell.
If you choose to make your feature hidden, you cannot have the Activation Dependency of the Enterprise Features. Just realize this means is that if you don’t have Enterprise Features turned on, this Content Type will not work.
Here’s a picture of where you’d make the feature hidden – it’s just another one of the properties on the feature:
Is Hidden is True
Deploy the feature, Activate it, and Use it
Once you deploy the solution package (.WSP file) and activate it to the site collection you’re going to use it in, it will now be a Content Type that you add to your Form Library. Any fields which you promoted in the Publishing process will automatically be added to your Form Library and will sync to the data in the form.
I got bits and pieces from a lot of places, but here’s some main ones that I got a lot of detail from: