Saturday, January 19, 2008

Deploying K2 InfoPath Web Enabled Forms with Managed Code

Deploying Web Enabled InfoPath Forms with .Net Managed has been a source of discussion for K2 BlackPearl. The challenge is that any InfoPath Form with .Net Managed code must be deployed through MOSS Central Administration. The following thread has been open for some time and continues to be an issue that has not been resolved -

The nexus of this challenge has to do with the requirement that MOSS enforces. It basically states that any InfoPath form that has .Net Managed code must be deployed through Central Administration. This is not the fault of K2 as I am currently unsure if this could even be done in an automate fashion as the MOSS team seemed to go out of their way to make sure that a system administrator have to manually upload the InfoPath template into Form Services.

The following are some good links to get an understanding of deploying InfoPath Forms with .Net Managed cod to SharePoint.

The deployment of the InfoPath form will be done using Content Types. This is because Central Administration will be push out to the InfoPath form to the Site Collections as a Content Type.

The following are some easy steps on how to deploy InfoPath Forms with .Net Managed Code with K2. The steps that are considered new outside of the standard process of deploying an InfoPath Form have been put in italics.

Create a K2 Process with an InfoPath Form with .Net Managed

The following steps will cover the addition of the InfoPath form to the K2 Process. It is recommended that you give the InfoPath form a unique name as the content type name will be the same as the InfoPath form name. Having a namespace like name for the form would be helpful.

  • Create a form and save it locally. Go to Form Options >> Compatibility >> Check "design this form so it can be opened over the web".
  • Create a form library.
  • Create a K2 Process Project.
  • Drag on the InfoPath Integration Process Wizard.
  • Add a Template. Select the form that was saved locally. On the deployment step select SharePoint and fill it in the site and library previously created. Select "Add as Content Type". Make sure you select Web Browser for the Form Client.
  • Finish the InfoPath Integration wizard.
  • Click the InfoPath Integration wizard icon in the top right hand corner and the Wizard will start up again. Select the form and press the design button.
  • Go to Tools >> Options >> Design >> set up the programming language appropriately. For instance select C# and enter the location where the .Net managed code project will be created.
  • To create the InfoPath form C# project, go Tools >> Programming >> Loading Event and the project will be created.
  • Save the form >> Close it >> Finish the Integration Wizard.

Corresponding Step Notes:

  1. The form you save locally will not be used moving forward and can be deleted.
  2. None
  3. None
  4. None
  5. None
  6. This is the step where the form will become K2 enabled. Several new data connections are added, the main data source has new elements added, new rules are added to both the submit and open events, etc.
  7. None
  8. This step could have been done prior to the InfoPath form being added to the K2 Solution. Although it is better to do it here because a resulting .Net Project can be added to the K2 Solution as another project. When setting the location, set the location to the same folder where the K2 Process project resides. Then in the K2 Solution select File >> Add >> Existing Project and find the .csproj.
  9. This event handler can be deleted if it will not be used.
  10. None

Deploying the First Time

The following steps would be done the first time the form is deployed. Laying this down will significantly simplify the deployment process of future forms.

  • Open the solution in Visual Studio.
  • Right click the K2 Process; finish the Deploy Wizard.
  • Close Visual Studio.
  • Then go to file explored >> find the K2 Solution >> go to the "InfoPath Form Templates" folder. Make a copy of the InfoPath form in there.
  • Go to the top site level in MOSS >> Site Settings >> Site Content Type Gallery. Find the content type for the InfoPath form located in "InfoPath Content Types" group; it should be the same name as the form. Delete the content type.
  • Get the InfoPath form that was deployed to the SharePoint server. There is a folder call "K2 BlackPearl InfoPath Form Templates". Find the template that was just uploaded. Right click it >> select "save target as" >> find the K2 solution >> go to the "InfoPath Form Templates" folder >> save the .xsn on top of the existing one.
  • Go to MOSS Central Administration >> Application Management >> Manage Form Templates.
  • Click the Upload Form Template button >> browse to the K2 solution >> go to the "InfoPath Form Templates" folder >> select the .xsn file >> press the Upload button.
  • Go back to the Manage Form Templates screen and wait to the status changes from "Installing" to "Ready".
  • Select the dropdown on the form and select "Activate to a Site Collection". Pick the site collection and press OK. Note that a new group called "Microsoft Office InfoPath" has the content type.
  • Go back to the form library. Select Settings >> Form Library Settings >> Advanced Settings >> Remove all of the content types. Then press the "Add from existing site content types" >> Find the content type in the "Microsoft Office InfoPath" group >> Press the Add button.

Corresponding Step Notes:

  1. None
  2. None
  3. None
  4. This is not required.
  5. This was the content type that was created during the K2 deployment. This will get recreated in later steps.
  6. When the InfoPath form was deployed it was deployed as a content type by K2. The InfoPath form template was placed into this folder which was created by K2. The InfoPath form that was deployed here is different that then form that is local. Most notably the data connections are all different. Before they were pointing directly to web services, but they are now pointing to data connection library called "K2 BlackPearl Data Connections" which in turn points to the web services.
  7. None
  8. None
  9. None
  10. The activation of the form will create a new content type on the site collection. We deleted the first content type because MOSS will not overwrite an existing content type. So if we did not delete the first content, we would now have two content types and only one of them would work as a Web Enabled .Net InfoPath form. Plus when K2 deploys the content type to a group called "InfoPath Form Templates" while MOSS Central Administration puts it in "Microsoft Office InfoPath". This is a little confusing but what has been observed.
  11. You can use the form library you created earlier or just create a new one. Since this is done as a content type now, it no longer matters what library the InfoPath form is deployed to.

WISH LIST - One thing that would make this less complicated is if it were possible to select or create existing Content Type Group on the server and have ability to specify your own Content Type name in the InfoPath Integration Wizard. In the .kprx file, where the definition of the InfoPath process resides, there is a PropertyWizardDefinition node. Within it there are tags such as DeployBrowserEnable, AddAsContentType and OpenAsWebPage however nothing to control the actual name of the content type.

Deploying Changes to the Form

The following steps would be used to redeploy your form.

  • Open the solution in Visual Studio.
  • Click the InfoPath Integration wizard icon in the top right hand corner and the Wizard will start up. Select the InfoPath form and press the Design button.
  • Make changes to the InfoPath form (important note below).
  • Save InfoPath >> Close the form >> press the Finish on the Wizard.
  • Right click the K2 Process; finish the Deploy Wizard.
  • Go to Central Administration >> Application Management >> Manage Form Templates.
  • Click the Upload Form Template button. Browse to the K2 solution and go to the "InfoPath Form Templates" folder and select the .xsn file. Press the Upload button.
  • Go back to the Manage Form Templates screen and wait to the status changes from "Upgrading" to "Ready".

Corresponding Step Notes:

  1. If you always want to be safe, just follow the steps above and ignore this note. K2 would always recommend redeploying the K2 Process when you make a change to the InfoPath form to make sure it remains in sync. If you are making changes to your InfoPath form that do not affect the datasource schemas (main or secondary) you do not need to redeploy K2 process. If you are changing a color, re-organizing presentation, adding rules, condition formatting, etc. you can just simply go to the form outside of Visual Studio, make your changes, and go to step 6. Make sure you still understand the nature of your change. For instance, if you change make a field not required anymore, you must check to see if that field is used in the K2 process you could have some un-desirable results.
  2. None
  3. IMPORTANT - If a new secondary data connection is added or the schema has changed, you must go back to Deploy the First Time instructions and repeat step 6. This will make sure that the data connection to the MOSS connection library is properly referenced in the form that will be deployed into central administration.
  4. None
  5. None
  6. None
  7. It is possible that you may receive an error "A form template with this file name already exists on the server. Rename the form template and try again". To resolve this >> deactivate the form >> deleted it >> continue with the steps.
  8. None


Following these steps allowed for an acceptable solution around redeploying web enabled InfoPath forms for K2. The redeployment of the forms is really quick and not that hard after the one time set up.


Senthil Kumar said...

If you want another way to deploy the infopath forms try this..


Tao Zhang said...

This will only work if the K2 process is started by the InfoPath form, in which case the form was created by the Forms Service and it has the correct reference to where the form template is. The K2 process only needs to provide the information as where is the sharepoint web site and the name of the form library when the form is rendered again in the rest of the process. However it falls flat if the process is not started by the form, in which case the process creates the InfoPath form automatically to start with and it has the WRONG reference to where the form template is. The form can not be opened even if you deploy it properly because that will not be the template the K2 generated form is referencing to. I am right in the middle of dealing with this and I am planning to use SharePoint event to correct the K2 created forms. But why K2 doesn't offer a less automated way to deploy InfoPath forms???? I wouldn't mind some extra configuration for the flexibility.

Jason Apergis said...


Yes there are some major challenges with working with InfoPath forms with .NET managed code. This is why I have said that if you have .NET managed code, use That is more of a general point, not directed at K2.

Anyways, the reason why K2 has challenges with InfoPath forms with .NET managed code is that the form must be deployed by a person with admin rights. Obviously a developer working in Visual Studio with K2 may or may not have those rights. It is a major short coming for heavy duty InfoPath integration with K2. None of the other BPA providers have a good answer for this either.

I suggest you make a comment to K2 directly - I do not work for them.

I have done what you are talking about where an InfoPath process was not initiated by an InfoPath form but it was in the 2003 days. The trick at that time was manually going into the InfoPath XML and making sure all the fields under _K2 were set correctly.

If you do not like the way K2 is deploying the forms another approach is check out my blogs here:

I developed these blogs for a NON-K2 solution I did for InfoPath. It deploys an InfoPath form as a feature and creates a content type for that form.

I CANNOT claim this will work because I have not tried it. Plus it really does not solve the problem you are complaining about. All this will do is get your form deployed as a content type and then you can reference that InfoPath content type from the K2 process. I have not test it - so do not blame me if it does not work :-)

Tao Zhang said...

Thanks Jason. That is much appreciated. I did think you were working for K2. Apologize.

Jason Apergis said...

I am actually a consultant and I am in the K2 Insider Program (basically a MVP for them)...