Deploying InfoPath templates within MOSS 2007

I am going to start with a quote that I want everyone to remember.  It should be in the mind of anyone developing InfoPath solutions for SharePoint.

“Never, ever publish an InfoPath form directly from InfoPath into a production SharePoint environment.”

I have seen this too many times and it will make your administrators really rather grumpy.  The reason is that although InfoPath will package your form up in a WSP (that’s a good thing), unfortunately it will give the WSP and the associated feature a GUID for a name (although the feature will display an appropriate friendly name in the UI.) 

What’s the problem with that?  Well, the problem will come when you try and find the WSP or feature that deploys your form because you want to make some change.  You’ll end up trawling through the feature directory to find the folder which contains your template.

A much better solution is to develop your own feature to deploy your form template, and to do this is really rather simple, more information can be found here.

The real benefit to deploying your templates in this fashion is that you can deploy your feature within your own WSP.  Rarely have I come across a SharePoint project which is just a single InfoPath form,  more likely it’s a series of forms, or more often a form as part of a wider solution involving workflow, event receivers and other components.  Therefore being able to bundle this feature in with other components in your WSP can prove invaluable.

What happens during feature deployment?

If you have followed the instructions within the article above then you will be using a feature which utilises the XsnFeatureReceiver class from within the Microsoft.Office.InfoPath.Server assembly.  But what does this feature receiver actually do?  It has two functions as far as I can tell:

  1. In the FeatureInstalled event of the feature receiver any .xsn files included within the feature are registered to the farm using the RegisterFormTemplate method of the FormTemplateCollection.  These will then show up in Manage Form Templates within Central Administration.
  2. In the FeatureActivated event of the feature receiver (this is run when you activate the appropriate feature in Site Collection Features) the form template is copied to the FormServerTemplates directory within the root web of the site collection.  At the same time a site content type is created which uses this template and which includes the fields promoted within the template.  It’s more difficult to know exactly what this code is doing as the code has been obfuscated.

These are just some insights and thoughts around this process.  There does seem to be a lot of information out there but I cannot find one clear guide on the whole process.  This might be a subject for a future article.