高分!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);
}

在下载按钮里点击没反应 也没报错就是无法实现压缩 小弟真是不解了 各位大哥、大姐,小弟在线等候,虚心求教啊!
...全文
140 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tonghui211306 2011-11-29
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 xinglang123 的回复:]

string DFilePath = @"D:\lianxi\xiazai\btn_ico";//需要压缩的文件夹 btn_ico
string DRARName = "abniu.zip"; //压缩后的文件夹名字
string DRARPath = @"D:\lianxi\xiazai\abc"; //压缩后压缩文件的存放位置

那我这样的 路径写法应该也没错的啊!代……
[/Quote]

"a-afzip" + "strR" + DRARName + "strF " + DFilePath + "-epl";//
he_Info = " a -ep " + packagepath + " " + filepath + " -ep ";

路径相同,命令不同啊。
小刘哈哈 2011-11-29
  • 打赏
  • 举报
回复
string DFilePath = @"D:\lianxi\xiazai\btn_ico";//需要压缩的文件夹 btn_ico
string DRARName = "abniu.zip"; //压缩后的文件夹名字
string DRARPath = @"D:\lianxi\xiazai\abc"; //压缩后压缩文件的存放位置

那我这样的 路径写法应该也没错的啊!代码也和你一样 为什么我就是实现不了 压缩呢?
tonghui211306 2011-11-29
  • 打赏
  • 举报
回复
packagepath
filepath
目标路径和源文件路径,程序里的路径拿不准的就在前面加上@,保证正确。
小刘哈哈 2011-11-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tonghui211306 的回复:]
the_Info = " a -ep " + packagepath + " " + filepath + " -ep ";
//得到转换文件的对象,格式: //命令(不可更改) + 压缩后文件名 + 被压缩的文件或者路径
[/Quote]

可以给我看下 你这里 压缩文件名 和被压缩的文件或者路径是怎么写的吗?
小刘哈哈 2011-11-29
  • 打赏
  • 举报
回复
奇怪了 在ASP中为什么 会没有 response这个属性呢?想照你的方法来试下 结果输不出 response 但我们其他的代码都一样,为什么我这就不能实现压缩呢?是路径的问题吗?
小刘哈哈 2011-11-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tonghui211306 的回复:]
the_Info = " a -ep " + packagepath + " " + filepath + " -ep ";
//得到转换文件的对象,格式: //命令(不可更改) + 压缩后文件名 + 被压缩的文件或者路径
[/Quote]

这个方法刚试了一下 还是 一样啊
the_Info = "a-ep" + DRARName + DFilePath + "-ep";//这样也不行 还是点击了没反应
tonghui211306 2011-11-29
  • 打赏
  • 举报
回复
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
//调用winner命令,此句不可更改

the_Obj = the_Reg.GetValue("");
//得到winner的对象。此句不可更改

the_rar = the_Obj.ToString();
//将此对象转换为实体。表示实际的对象。

Response.Write(the_rar + "<br>"+DateTime.Now.ToString());
//值为"C:\Program Files\WinRAR\WinRAR.exe" "%1"
the_Reg.Close();

the_rar = the_rar.Substring(1, the_rar.Length - 7);
//获取winner对象的实体的类型

Response.Write(the_rar+"=="+DateTime.Now.ToString());
//值为:C:\Program Files\WinRAR\WinRAR.exe

the_Info = " a -ep " + packagepath + " " + filepath + " -ep ";
//得到转换文件的对象,格式: //命令(不可更改) + 压缩后文件名 + 被压缩的文件或者路径

the_StartInfo = new ProcessStartInfo();
//初始化进程对象

the_StartInfo.FileName = the_rar;
//得到初始化进程对象文件名

the_StartInfo.Arguments = the_Info;
//传入对象的参数

the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//指定系统启动进程是的窗口状态
the_StartInfo.WorkingDirectory = @"C:\1";

//获取或设置要启动的进程的初始目录。

the_Process = new Process();
//进程初始化开始对象实例
the_Process.StartInfo = the_StartInfo;
//传递进程的属性

the_Process.Start();
//开始压缩

Response.Write("压缩成功");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
tonghui211306 2011-11-29
  • 打赏
  • 举报
回复
the_Info = " a -ep " + packagepath + " " + filepath + " -ep ";
//得到转换文件的对象,格式: //命令(不可更改) + 压缩后文件名 + 被压缩的文件或者路径
tonghui211306 2011-11-29
  • 打赏
  • 举报
回复
the_Info = "a-afzip" + "strR" + DRARName + "strF " + DFilePath + "-epl";//命令+压缩后文件名+被压缩的

这个地方压缩命令有问题吧。你百度下看看,我两年前做过一个,现在忘记了。

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧