Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

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

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

  • Comments 1

 

Part 4 of 5: Repacking the XSN

 

For packing algorithm we will use another useful utility from the Cabinet SDK which called “makecab.exe”. It can be found in the same place where extract.exe lives.

 

This utility needs some data description file that we will build automatically from the XSF file.

 

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

var MakecabExe = Combine(MakecabExeLocation, "makecab.exe");

 

function SaveToFile(data, filePath)

{

      var Fso = new ActiveXObject ("Scripting.FileSystemObject");

      Fso.CreateTextFile(filePath, true);

      var TextStream = Fso.OpenTextFile (filePath, 2);

      TextStream.Write(data);

      TextStream.Close();

}

 

function MakeXSNFromFiles(

      inputDirectory,

      xsfName,

      outputDirectory,

      xsnName)

{

      var DDF = "";

      DDF += ".Set DiskDirectoryTemplate=\r\n";

      DDF += ".Set CabinetNameTemplate='"

            + Combine(outDir, xsnName) + "'\r\n";

 

      var Dom = new ActiveXObject("msxml2.domdocument.5.0");

      Dom.async=false;

      Dom.validateOnParse=false; // for ignoring xsi:nil errors..

      Dom.load(Combine(inputDirectory, xsfName));

      Dom.setProperty("SelectionNamespaces",

                  "xmlns:xsf='" + XsfNamespace + "'");

 

      DDF += QuoteStr(Combine(inputDirectory, xsfName)) + "\r\n";

      var Filelist = Dom.selectNodes("//xsf:files/xsf:file/@name");

      for (var i=0; i<Filelist.length; i++)

            DDF += QuoteStr(Combine(inputDirectory, Filelist(i).text))

                  + "\r\n";

 

      var DDFPath = Combine(outputDirectory, "makecab.ddf");

      SaveToFile(DDF, DDFPath);

      Exec(QuoteStr(MakecabExe)

            + " /v1 /f " + QuoteStr(DDFPath)

            + " /L " + QuoteStr(outputDirectory), true);

}

 

In the last fifth part of the discussion we will come up with the final function.

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post