Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

Modifying InfoPath manifest.xsf file from script (2/5)

Modifying InfoPath manifest.xsf file from script (2/5)

  • Comments 3

Part 2 of 5: Unpacking the XSN

To unpack XSN one should use extract.exe utility. It can be found in the %SystemRoot%\system32 directory or in the Microsoft Cabinet Software Development Kit. For the command usage details just run “extract /?”.

In this part we will also introduce several auxiliary functions that will be extensively used throughout the entire discussion topic.

var ExtractExeLocation = "%SystemRoot%\\SYSTEM32";

var ExtractExe = Combine(ExtractExeLocation, "extract.exe");

 

function Combine(dir, file)

{

      return dir + "\\" + file ;

}

 

function QuoteStr(string)

{

      return ("\"" + string + "\"");

}

 

function Exec(string, flagWait)

{

      if (flagWait == null)

            flagWait = true;

      var WScriptShell = WScript.CreateObject("WScript.Shell");

      return WScriptShell.Run(string, 0, flagWait);

}

 

function ExtractFilesFromXSN(xsnInputPath, outputDirectory)

{

      var Parameters;

 

      // add the location to place extracted files,

      // a flag "/Y" that prevents prompting before overwriting

      // an existing file, and a flag "/E" that orders to

      // extract all files

      if (outputDirectory != null)

            Parameters = " /Y /E /L " + QuoteStr(outputDirectory);

 

      Exec(QuoteStr(ExtractExe)

            + Parameters

            + " " + QuoteStr(xsnInputPath), true);

} 

Now we have a tool to unpack XSN. All of the InfoPath form template files are accessible for changing. In the next part of the series we will be modifying the manifest itself.

Leave a Comment
  • Please add 6 and 4 and type the answer here:
  • Post
  • How to programmatically extract/manipulate/combine an InfoPath Template (XSN) file.
  • Nice Article :)

    Another simple way to extract XSN file is,

    expand -F:* "C:\Old XSN\Testing.xsn" "C:\ExtractedXSN"

    Above command will extract Testing.XSN file to C:\ExtractedXSN folder.

Page 1 of 1 (3 items)