Publishing InfoPath web form using stsadm command line utility
 
In this article, we will see how to publish an InfoPath web form using an stsadm command line utility. In the previous article "Creating Web Enabled InfoPath Form", we saw how to publish the form using SharePoint Central Administration site, that is, using the web interface. In large organizations that have multiple departments and servers running multiple applications at a time, deploying forms manually may not be a good idea because it will never be a one time deployment. In big organzations, the applications are released in steps and there is version control. Also, there are bug fixes and there is a need for an easy deployment method that does not involve developer interaction. Administrators can create batch files to upload and deploy the forms. Stsadm.exe utility comes in handy when there is a need for such tasks. This utility does a lot of other things which we won't discuss here as they are not relevant but some commands that are important will be discussed in detail.

Ok, the form is ready. We already deployed it using the interface. Now we will deploy it using the command line tool. The first command that we will look at is following:

stsadm.exe -o VerifyFormTemplate -filename "C:\Forms\userregistrationtpl.xsn"

The operation that we use in this command is "VerifyFormTemplate". It verifies that the template is free of errors. In case there are errors, they will be displayed in the console window. The parameter we used is "filename". This is the complete file path on your disk. It is important that you run this command before uploading the form on the server. There are some errors that cannot be caught during the upload process. Your template won't work even if the uploading is successful. The only way to make sure that there are no errors in your form are to run this command.

You can also use the "Design Checker" in InfoPath to check for errors.

design checker

You can also use "Logic Inspector" to find errors in your logic, rules, etc but there is no guarantee that your form will be free of errors even after running these tools. Yes, I agree this does not make sense. There should be a way to test the form for errors before handing it over to the Administrator but that's the way InfoPath works. The only way to make sure that form template is free of errors is to use the "VerifyFormTemplate" operation with stsadm.exe command.

The second command is for uploading the template to the server:
stsadm.exe -o UploadFormTemplate -filename "C:\Forms\userregistrationtpl.xsn"

We use "UploadFormTemplate" operation to upload the form. The "filename" parameter contains the full path of the file on your disk.

The third command is for activating the template on the server. The operation that we use is "ActivateFormTemplate" and we pass two parameters. The first one is "URL" which is the site collection URL where you want to activate the template. The second parameter is "filename" which is the full path of the template on the disk.
stsadm.exe -o ActivateFormTemplate -url "http://server" -filename "C:\Forms\userregistrationtpl.xsn"

There is another way of activating the form on the site. You have seen two methods already. The third one is through the interface but not central administration this time. Just go to the SharePoint root site. Go to :"Site Settings".  Under "Site Collection Administration" you will find a link "Site collection features". Click it. Find your template in the list. You will see "Activate" button in front of the template name. Click it to activate the template. Similarly to deactivate it, click the "Deactivate" button (Activate will turn into Deactivate once the form is activated). The status is shown next to the button.

Ok, now you have activated the form. There should be a way to deactivate and remove the form from the server. The command to deactivate the form on the server is as following:
stsadm.exe -o DeactivateFormTemplate -url "http://server" -filename "C:\Forms\userregistrationtpl.xsn"

This command will deactivate the template. The parameters are "URL" and the "Filename".

To remove the form from the server, use following command:
stsadm.exe -o RemoveFormTemplate -filename "C:\Forms\userregistrationtpl.xsn"

This will remove the template from the server. The only parameter is "filename".

You will get an error if the following service is not running on the server:
Windows SharePoint Services Administration

Go to Control Panel and Service and start this service if it's not already started. You can also use another stsadm command to run the administrative service jobs in which the Windows SharePoint Services Administration (SPAdmin) service has been disabled. The command is:
stsadm -o execadmsvcjobs

This will execute the pending jobs on the server. Sometimes, you will get the following error.
The solution-deployment-jobxx.wsp-0 job completed successfully, but could not be properly cleaned up. This job may execute again on this server. Operation completed successfully.

Ignore the error. The job has been run.

Create a batch file and add all the commands shown above to automate the deployment process. If the form is already deployed and you just want to upgrade the template, use the following command:
stsadm.exe -o UpgradeFormTemplate -filename "C:\Forms\userregistrationtpl.xsn"

This will upgrade the template. If you made changes to the promoted fields, for example, promoted new fields or demoted some of the already promoted fields, you will have to reactivate the template on the server for the changes to take effect.

That's it. Hope you like the article.