server端多个文件的压缩 .NET

server端多个文件的压缩

今天编写程式,内容是把处理过的文件保存到Client端。由于文件较多可能的20个以上,我考虑现压缩,然后把压缩的文件下载到客户端.
压缩代码如下:
int XRFbeginPage=(int)Session["XRFbeginPageTemp"];
int sheetAmount=(int)Session["sheetAmountTemp"];
string rarfileexe=@"D:\Program Files\WinRAR\WinRAR.exe";
string sourcefile="";
string targetfile=@"d:\temp\rar\"+DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+".rar";//choice path
string shellCommand="";
//long result;
int Rarnumber=0;
int i;
for (i=XRFbeginPage;i<=sheetAmount-XRFbeginPage;i++)
{
sourcefile+=@" E:\work1025\WebNetProcess\txt\"+i.ToString()+".txt"+" ";
Rarnumber++;
}
shellCommand=string.Concat(" A -ep1 -inul -y ",targetfile," ",sourcefile);
//System.Diagnostics.Process.Start(shellCommand);

System.Diagnostics.Process Process1=new System.Diagnostics.Process();
Process1.StartInfo.FileName=rarfileexe;
Process1.StartInfo.Arguments=shellCommand;
Process1.Start();
while (!Process1.HasExited)
{

}

关键的几行代码是:
System.Diagnostics.Process Process1=new System.Diagnostics.Process();
Process1.StartInfo.FileName=rarfileexe;
Process1.StartInfo.Arguments=shellCommand;
Process1.Start();
while (!Process1.HasExited)
{

}
压缩完文件之后就可以考虑把压缩的文件下载到客户端

执行外部程序的另外的方法:
   AppDomain currentDomain=AppDomain.CurrentDomain;
   Console.WriteLine(currentDomain.FriendlyName);
   AppDomain secondDomain=System.AppDomain.CreateDomain("NewAppDomain1");
   secondDomain.ExecuteAssembly("testQQClient.exe");
posted @ 2004-12-22 08:45  jhtchina  阅读(1236)  评论(0编辑  收藏  举报