高分!ASP中对文件夹进行压缩 问题,大哥小弟在线求教啊!
小刘哈哈 2011-11-29 03:08:52 这是我压缩的代码:
public static bool CompressRAR()
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
string DFilePath = @"D:\lianxi\xiazai\btn_ico";//需要压缩的文件夹 btn_ico
string DRARName = "abniu.zip"; //压缩后的文件夹名字
string DRARPath = @"D:\lianxi\xiazai\abc"; //压缩后压缩文件的存放位置
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"D:\lianxi\xiazai\Win\WinRAR.exe\Shell\Open\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = "a-afzip" + "strR" + DRARName + "strF " + DFilePath + "-epl";//命令+压缩后文件名+被压缩的文件或者路径
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = DRARPath;//RaR文件的存放目录
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
return true;
}
catch(Exception ex)
{
return false;
}
}
下载按钮的调用:
protected void Button3_Click(object sender, EventArgs e)
{
CompressRAR();
//Response.ContentType = "application/x-zip-compressed";
//Response.AddHeader("Content-Disposition", "attachment;filename=z.zip");
//string filename = Server.MapPath("btn_ico/abniu.zip");
//Response.TransmitFile(filename);
}
在下载按钮里点击没反应 也没报错就是无法实现压缩 小弟真是不解了 各位大哥、大姐,小弟在线等候,虚心求教啊!