I recently was handed a project that consisted of an InfoPath form with code behind, as well as a workflow with custom InfoPath forms. The code was in visual studio 2005 projects, and was packaged into SharePoint wsps using wspbuilder. This blog article only concentrates on deploying the InfoPath form with code behind as a SharePoint wsp, using wspbuilder (http://www.codeplex.com/wspbuilder).
A rough outline of the structure is as follows:
- Infopath originals xsn’s existing outside of the visual studio 2005 solution.
- The infopath forms were then published into a features folder of a project that used wspbuilder to construct a wsp. Note that infopath threw “unknown errors” in the preexisting published xsn file was not checked out. Also note that the feature uses the XsnFeatureReceiver.
- The code behind for the infopath form existed in a vsta project, which resided in the solution. Note that when editing this code, I always initiated this from Infopath, and not from Visual Studio directly. The output assembly was then automatically bound into the xsn by vsta and published to the project containing the feature folder.
- The project containing the feature was then built – a wsp was subsequently generated and deployed.
After doing the above, I got the following error:
System.IO.FileNotFoundException: Could not load file or assembly file:///C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Features\<MyFeatureFolder>\<InfopathCodeBehind>.dll or one of its dependencies. The system cannot find the file specified.
It turns out that when the xsn is deployed through upload form template on the applications tab of central admin, a feature is created on the fly on the file system. When this feature is created, SharePoint extracts the dll from the xsn so that the dll sits beside the xsn in the features folder. See the screenshots below.
This was a little surprising that it is extracted, as the dll exists in the xsn. Anyway, from that, I altered feature so that it contained the dll extracted from the xsn. Note that this was a manual step – to do this i did the following:
- Copy xsn file and rename .cab.
- Extract dll from .cab and put in relevant location in your features folder
- Ensure that feature.xml and elements.xml contain a reference to the dll.