This post talks about using stsadm and batch scripts to deploy InfoPath form with code behind which usually is called as InfoPath forms with managed code or the InfoPath forms managed templates.
The problem: If it’s just a couple of InfoPath forms with simple code behind we can deploy the form using the InfoPath Forms Client application itself. As laid out neatly here. To summarize, it involves the following steps:
- Publish to a network location
- Verify its browser compatible while uploading to InfoPath managed templates in Central Admin.
- Upload to InfoPath managed templates found in Central Administration
- Wait for the status to upload complete.
- SharePoint admin should activate it for a particular site where the developer want to use it.
- Wait for the activation to complete.
Imagine doing all this every time you make change to the code behind of the form or change the user interface. The worst part is waiting for the status to get completed as SharePoint does those kind of jobs based on the timer job service. To run these tasks forcefully the stsadm’s execsrvcjobs command operation comes handy.
Below is the script to install a new infopath form template and activate for a particular site collection:
::Publish the form to a location lets say it is published at C:\InfoPathForms\Publish\sample.xsn
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
::uncomment the below three lines if you want to uninstall and re-install the infopath form template
::stsadm.exe -o DeActivateFormTemplate -url http://demosite -filename ::C:\InfoPathForms\Publish\sample.xsn
::stsadm.exe -o RemoveFormTemplate C:\InfoPathForms\Publish\sample.xsn
::stsadm.exe -o execadmsvcjobs
stsadm.exe -o verifyformtemplate -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o UploadFormTemplate -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o execadmsvcjobs
stsadm.exe -o ActivateFormTemplate -url http://demosite -filename C:\InfoPathForms\Publish\sample.xsn
Below is the script to upgrade or update the existing infopath form template for a site collection:
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
stsadm.exe -o DeActivateFormTemplate -url http://demosite -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o verifyformtemplate -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o UpgradeFormTemplate -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o execadmsvcjobs
stsadm.exe -o ActivateFormTemplate -url http://demosite -filename C:\InfoPathForms\Publish\sample.xsn
UPDATE: If you just changed the code behind of the form and want to deploy it there is even better and quicker way to do it. When the form is deployed using the above stsadm scripts what it does is, it depoys the form as a content type feature and the folder name is some what like FT- which is found under C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\
Under this you will find folder liek solution.xsn.1.0.0.210.1.0.0.210. Find the latest one and drop the updated DLL’s in there and then reset the IIS or recycle the app pool for the site collection. That is it!!
PS: I got the initial help of preparing the batch script from here.
Filed under: InfoPath Forms, Sharepoint | Tagged: InfoPath Forms, Sharepoint

Thanks for the info. While this works well, it would not work for form templates that are associated with a custom workflow. The only way I have found the update a form is to redo the feature.
[...] whole process is long and gruesome if we have to repeat for many forms so I posted some time back on how to use stsadm.exe script to upload/delete/update the managed form templates. [...]
I get object reference not set to an instance of an object.
Hai All,
Infopath forms with managed code behindd can be published from the Central Admin.Complie the solution file,and place it in the same folder where the form is published,and when the form is uploaded in the Central Admin and activated it automatically create it as a feature in the features folder eg:(C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\FT-01-064abfd8-9833-3027-a083-a39d18a54cb5\solution.xsn.1.0.0.8) under which the solution.xsn and the application dll are located.if the dll is not copied you can manually copy the dll and reset the iis or reset the app pool,thi swill solve the issue.
Good post. I am still getting the following error when I tried to activate the form from CA – see below.
”
The form template could not be activated to the following site collection: http://mysitecollection:62000. You do not have the permissions required to perform this operation. Only the administrators of this site collection can activate to the site collection. Either add yourself as a site collection administrator, or have a site collection administrator activate the form template”.
The port number is a part of site collection name.
The form relies on one webservice and I am the site collection admin.
Any ideas?
Chriss… I would try troubleshooting this as follows: Making sure the login you are using with central admin is also the admin for the site collection for which you are activating the form. Verify the form is compatible with the site collection. If u think web service data connection is the issue, you can just remove that data connection and its dependencies and try deploying the form. Also, dont forget to check the eventviewer logs.. As per error message, even you have proper permissions you should never have problems… As a final resort, 12 hive logs for any more info.
[...] Using stsadm to deploy, upgrade, update InfoPath Forms Templates with Managed code behind. Fuente: Blog de Srinivas Varukala. En este caso, el artículo describe como automatizar la publicación de un formulario utilizando STSADM. [...]
[...] Using stsadm to deploy, upgrade, update InfoPath Forms Templates with Managed code behind. Fuente: Blog de Srinivas Varukala. En este caso, el artículo describe como automatizar la publicación de un formulario utilizando STSADM. [...]