«

Accessing CAB File (or InfoPath template) Contents From Managed Code

One of the challenges my team has faced in building a solution using InfoPath is the difficulty of testing forms which are published to a specific url. Creative use of a HOSTS file can be helpful, but sometimes it’s just not possible to support all of the features such as SSL. If the form is supposed to run from “httpS://prodserver” it may not be possible to test it in the stage environment. This has led to some embarrassing production issues for us, due to typos and the like. Add some interesting custom magic we do in our process to the mix and things can get tricky. Well, checking for typos is something that computers do very well.


So, we decided to create an automated post publish utility to verify things like the publishUrl, solutionVersion and other things that are required in our view stylesheets. The only annoying part of the process was having to manually rename the XSN file as a CAb, extract the contents to a folder, and then clean up the files. Wouldn’t it be great if there were a way, preferably managed, to automate that part of the process?



Stepping back, it’s important that you understand that an InfoPath Form template (an XSN file) is just a CAB file with a different extension. Change the file extension on any .XSN file you’ve created to .CAB and you can open it with your CAB viewer of choice (say XP’s compressed folder support). Now, back to our story…

I looked into implementing a managed wrapper for the CAB APIs myself, but it seemed like it would take longer than my budget for the feature would allow. Well, luckily enough, I stumbled onto Jim Mischel’s great article “Creating an Object-Oriented Interface to CAB Files” which includes a code sample for doing just that. I wasn’t able to get the compression portion of his code to work, but the extraction bits suited us to a tee and our used by our utility as we speak. Now testing the published XSN files is as simple as pointing a console exe at the appropriate file and letting the code do it’s magic.

Of course, I’ve yet to hear any thanks from the build manager ;).