过去做过的项目,需要根据项目的配置动态生成Infopath模板(.xsn文件)。Infopath模板本质是一个cab包,其中包含dll、布局文件和配置文件(xml)。
动态生成的思路:新建一个文件夹,把需要打包的文件复制进新文件夹中,然后起一个新的进程,运行.bat,打包签名。
//列出需要打包的文件名并复制到新文件内
string[] strFileList = {"make.bat","CABARC.EXE","______.dll","ConfigXmlTest.xsd","manifest.xsf","myschema.xsd","sampledata.xml","template.xml","upgrade.xsl","view1.xsl","view2.xsl","view4.xsl","view6.xsl","signtool.exe","***.pfx","sign.bat"};//根据实际情况修改,.pfx为签名文件
foreach (string strSingleFilePath in strFileList)
{
File.Copy(Server.MapPath("XsnMaker") + "\\" + strSingleFilePath, strRandomFolderPath + "\\" + strSingleFilePath);
}
string strExcute = strRandomFolderPath + @"\make.bat";
try
{
//用本地批处理文件,把上述文件打包
string batUpPath = Server.MapPath("CreateBat");
string batpath = batUpPath + @"\make.bat";
Process p = new Process();
p.StartInfo.FileName = strExcute;
p.StartInfo.WorkingDirectory = strRandomFolderPath; //这一条语句不能遗漏
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.RedirectStandardInput = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
//签名
Process oProcessSign = new Process();
oProcessSign.StartInfo.FileName = strRandomFolderPath + @"\sign.bat";
oProcessSign.StartInfo.WorkingDirectory = strRandomFolderPath;
oProcessSign.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
oProcessSign.StartInfo.UseShellExecute = false;
oProcessSign.StartInfo.RedirectStandardOutput = false;
oProcessSign.StartInfo.RedirectStandardInput = false;
oProcessSign.StartInfo.CreateNoWindow = true;
oProcessSign.Start();
oProcessSign.WaitForExit();
//生成模板文件并?名之后,删除不需要的文件,节省服务器空间
foreach (string strSingleFilePath in strFileList)
{
File.Delete(strRandomFolderPath + "\\" + strSingleFilePath);
}
File.Delete(strRandomFolderPath + "\\" + "ConfigXmlTest");
}
catch (Exception ee)
{
Response.Write(ee.Message);
}make.bat :
cabarc -s 6144 n ******.xsn *.dll *.inf *.txt *.xsd *.xml *.xsf *.xsl ConfigXmlTestsign.bat :signtool sign /f ***.pfx /p 123456 ******.xsn注:***表示签名文件,******表示打包之后的文件名(如果只是打包成cab,则扩展名改为.cab)
cabarc和signtool可以在网上下载。
本文详细介绍了如何根据项目配置动态生成Infopath模板(.xsn文件),包括打包、签名等步骤,以及所需的文件列表。

763

被折叠的 条评论
为什么被折叠?



