制作cab文件并签名(动态生成infopath模版)

本文详细介绍了如何根据项目配置动态生成Infopath模板(.xsn文件),包括打包、签名等步骤,以及所需的文件列表。

    过去做过的项目,需要根据项目的配置动态生成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 ConfigXmlTest
sign.bat :
signtool sign /f ***.pfx /p 123456 ******.xsn

注:***表示签名文件,******表示打包之后的文件名(如果只是打包成cab,则扩展名改为.cab)
        cabarc和signtool可以在网上下载。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值