There are a lot of instructions out there on how to publish InfoPath forms with code behind to SharePoint. However, I have not come across any complete documentation on how to do this from beginning to end with K2 BlackPoint to SharePoint. One of the problems that will usually arise is that if you have multiple activities with in the K2 workflow, you will not be able to surface the IP form to the browser in succeeding steps. Usually, the form will surface in the browser on the first activity and any subsequent activities will result in the IP form trying to open in the IP client. If you follow the steps that I am demonstrating, you will be able to successfully publish and use the IP forms with code behind in combination with the K2 workflow. One thing to note, this process is applicable to K2 BlackPoint and also K2 BlackPearl.
Enabling SSL on SharePoint Server
Prerequisite: Certification Authority (CA) needs to be installed on the Server or need access to a CA.
For more information regarding CA, please refer to the following links:
After you have created your InfoPath form that is browser-enabled and does utilize code-behind, you will need to log in to your SharePoint server. Open IIS manager and navigate to the SharePoint web application. Open the properties of this website and select the Directory Security tab. In the Secure communications section, verify that a certificate exists by clicking on the View Certificate button (figure A) and making sure the certificate is valid and issued to the website host-header. (figure B) If there is not a valid certificate, you will need to obtain a valid certificate for the site.
Create InfoPath Form Library
Log on to your SharePoint site as a Site Collection Administrator and create an empty Form Library. Once you have created the library, go to the form library settings and click on the libraries Advanced Settings. In the Content Types section, select Yes for the management of Content Types. In the Browser-enabled Documents section, select Display as a Web Page option. Click Ok.
Designing the InfoPath Form Template in K2
Assuming you have created a blank process in K2, click on the Process Wizard tab and drag InfoPath Integration onto the K2 process. Click on Add to insert a new InfoPath Form template. Configure the wizard screens as follows:
InfoPath Form Source Location
InfoPath Form Deployment Location
Finish out the InfoPath Integration wizard as normal and save the K2 project. Deploy the K2 solution as normal and verify that it was successful.
InfoPath Form Directories
At this point, a published form directory needs to be created. Create a folder on your local machine (i.e. C:\InfoPath Published Forms). This folder will be the “Published From” folder (will be referenced as IP_FROM). The folder that is “Published To” is the location of your K2 project, and browse to the InfoPath Form Templates folder (will be referenced as IP_TO).
Once you have deployed the K2 process successfully, browse to the IP_TO folder and copy the XSN template and paste it to the IP_FROM folder.
This next few steps is a workaround to keep the template file with the same name. Right click the XSN template in the IP_FROM folder and click Design.
(The following steps will only need to happen the first time the form is copied over to the IP_FROM folder. If you don’t receive the error, skip these steps below and go to the Signing and Publishing the InfoPath Form section)
You may receive an error message the first time that looks like the following:
Click OK and the form will open. Follow these steps:
- Go to File/Save As and save the file with a different name to the same directory that you just opened it from
- Close the form
- Locate the original template that you clicked Design and remember the name of the form template (should be the same as in the IP_TO folder) and delete the template
- Right click the new template that saved in step 1 and select Design.
- Go to File/Save As and save the file with the same name as the one you deleted in step 3
- Close the form
- Delete the form you saved in Step 1.
- Right click the form you saved in Step 5 and select Design
Reason for the steps above is that when publishing the form, SharePoint will use the name of the form as the content type, and we want it to be the same name as the one in the IP_TO folder.
Signing the InfoPath Form
The form should be in design mode from the IP_FROM folder as mentioned in the previous section. Here are the steps to publish the form:
- Go to Tools / Form Options and select the Security and Trust category
- Make sure the form is set to Full Trust
- Under the Form Template Signature section of the Security and Trust category, make sure that the checkbox is checked for Sign this Form Template and a certificate is associated with it (see figure C).
- Go to the Programming category of the form options and verify the project location is correct and that it has the project file name (.csproj) as well (see figure D).
- Got to the Compatibility category of the form option and verify that the box is checked to open the form template in a browser (see figure E)
- Click OK, but DO NOT close the InfoPath Form.
Publishing the InfoPath Form
Once you have completed verifying the correct code behind is associated with the form and have signed the form, you are now ready to publish the form.
- Go to File / Publish on the InfoPath form
Uploading and Activating InfoPath Form on SharePoint
At this point, you are ready to upload the form template to SharePoint. Open up an instance of SharePoint Central Administration and browse to Application Management. Locate the InfoPath Form Services section and click on Manage Form Templates. Click on Upload Form Templates link. In this screen, where the text box is to insert the file name, click the Browse button and navigate to the IP_TO folder where you just finished publishing the form to. Select the XSN file you published and click Open.
Click the Upload button and wait until the next screen appears showing the form uploaded successfully.
Once you click OK, it will return you to the Manage Form Templates page and verify the form you just uploaded is in the Ready status. If it is not, refresh the page until it is.
Navigate to your Site Collection and complete the following steps:
- Click on Site Actions of the site collection.
- Select Site Settings
- Under the Site Collection Administration section of the site settings, click on Site Collection Features.
- Locate the form template you just uploaded and click Activate.
- Now browse to your Form Library that you created earlier and select the form library settings
- Locate the Content Types section and click on Add from existing site content types.
- In the available content types box, select the content type (your InfoPath form name) and Add it to the box for content types to add and click OK.
- Click on Change new button order and default content type and uncheck the box to make the FORM content type NOT visible and change the position from top of your new content type to 1 and click OK.