Modify a XSN InfoPath by using makecab command

Sometimes you have to change manually any files for e.g. the .xsd schema in a InfoPath XSN file. But how can you build extracted XSN files back to a XSN formular? In this article I will show you how to realzie that.But before I give you some imformation about this unknown format.

Introduction:

InfoPath stores all necessary files (e.g Xml, Xsl, Xsd, Images, manifest etc.) in the compressed XSN format.The XSN is actually noting but a .Cab file (cabinet). Or you can change the datatype to a normal .zip. There are many scenarios where you might need to modify an InfoPath form template (.XSN) after it’s already in use. Let’s say the URL of your Web Service changes. Using this approach you can change not only URLs or Schemas but SQL connection strings, files names, etc. If you want to learn more about the XSN format and the files that make it up, check out the InfoPath 2003 SDK. As always, be careful – save backup copies, test your code, test the templates before and after.

If you are working with Sharepoint or Infopath sometime you need to use makecab.exe, it is a command line utility to create cab files from Microsoft. You can use makecab utility from command prompt.

The InfoPath XSN format is really a CAB file, and the files that make up the template are XML files which can easily be modified programmatically. You can pack/unpack a CAB file with help of extract.exe and makecab.exe utilities that are accessible for Windows users.

One of the files necessary to build a Microsoft cabinet (.CAB) file archive. The Diamond Directive File contains specific information required to compress your files into a cabinet (.CAB) file; the DDF file itself is not placed into the .CAB file. The file may be opened in any text editor. To build/rebuild a .CAB file, you must use the MakeCab.Exe utility.

Realization:

First unpack the XSN file by changing the datatype to .cab or .zip and extract the file. After you have modifyed all your files than you have to compress the folder back to an InfoPath datatype in the next step.

Now this is where you need to use a tool called Make-Cab which can be found in C:\Windows\System32\makecab.exe. Then you have to create a text for example makeXSN.txt file where you have to add all necessary files you need in your formular.

4 Responses to “Modify a XSN InfoPath by using makecab command”

This was a useful post. I have hacked together a simple batch file that will carry out the steps you discuss for a specified XSN or CAB file. It pauses mid execution to allow you to update the manifest.xsf file before automatically re-building the XSN in a subdirectory.

Somone with better batch skills that I could probably add a find and replace function somewhere in the middle.

Mr Tsaid

An easier solution is to use the cabarc utility (http://support.microsoft.com/kb/310618) and then use “cabarc N” with a list of the files you want in the xsn.. alternatively just “*” to cab all the files in the current directory.