DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Modify a XSN InfoPath by using makecab command

Posted by PANVEGA on January 5, 2008

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.


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.


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.


<!–[if gte mso 9]> Normal 0 21 false false false DE-AT X-NONE X-NONE MicrosoftInternetExplorer4 <![endif]–><!–[if gte mso 9]> <![endif]–> <!–[endif]–>


; MSDN Sample Source Code MakeCAB Directive file example




; change the value of the caninet name for example myInfoPath.xsn


.Set CabinetNameTemplate=AfterRePackaging.XSN


; change the value of the Disk Directory Template value to the directory you want to store the xsn file into,,


.set DiskDirectoryTemplate=”C:\Workarea\InfoPath Work”

.Set Cabinet=on

.Set Compress=on


; Just List All the files to be added in the xsn file


“C:\Workarea\InfoPath Work\Extracted Files\manifest.xsf”

“C:\Workarea\InfoPath Work\Extracted Files\myschema.xsd”

“C:\Workarea\InfoPath Work\Extracted Files\sampledata.xml”

“C:\Workarea\InfoPath Work\Extracted Files\template.xml”

“C:\Workarea\InfoPath Work\Extracted Files\upgrade.xsl”

“C:\Workarea\InfoPath Work\Extracted Files\view1.xsl”


; End of the File


After you added  all files go to command prompt cmd and tipe  MakeCab /f makeXSN.txt.txt. Now you have created a modified InfoPath formular.

More Information:


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

  1. tililudge said

    ehh.. bookmarked..

  2. Hi Panvega,

    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.



    @echo off
    REM — Prepare the Command Processor —

    echo::Unpackpack.bat – Expands a cab or XSN file for editing
    echo::then re-compresses it into \output directory
    echo:: Archive [in] – Name of .cab or .XSN
    echo::example: Unpackpack FormAgentUI.xsn
    IF %1==”” GOTO :EOF

    ::First expand the archive or XSF file into a temporary subdirectory
    makedir temp
    expand %1 -F:* .\temp
    ::Move to the temp directory and carry out the find and replace
    cd .\temp

    ::Pause to allow update of manifest.xsf
    echo Update the files in .\temp directory manually
    echo – eg. update UIComm references in manifest.xsf

    ::Create DDF file to re-create the CAB file
    del sample.ddf
    echo ;*** Sample Source Code MakeCAB Directive file example >sample.ddf
    echo ;>>sample.ddf
    echo .OPTION EXPLICIT ; Generate errors>>sample.ddf
    echo .Set CabinetNameTemplate=”%1″>>sample.ddf
    echo .set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory>>sample.ddf
    echo .Set CompressionType=MSZIP;** All files are compressed in cabinet files>>sample.ddf
    echo .Set UniqueFiles=”OFF”>>sample.ddf
    echo .Set Cabinet=on>>sample.ddf
    echo .Set DiskDirectory1=”output”>>sample.ddf
    dir *.* /b /A-D >>sample.ddf
    echo ;*** the end>>sample.ddf

    If Exist .\output\%1 del .\output\%1
    makecab /f sample.ddf

  3. hodzanassredin said

    wrote small tool for edit xsn/cab files . It just call external commands and do all magic for you :-)

  4. Mr T said

    An easier solution is to use the cabarc utility ( 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: