请问用asp.net如何对服务器上的一个文件夹进行压缩

Nihn 2009-04-13 05:11:00
如题。
网上找了一些例子,但都是对文件进行压缩,请问该如何对文件夹进行压缩。
谢谢!
...全文
86 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
快40的码农 2009-04-13
  • 打赏
  • 举报
回复
我实际项目中用的方法
快40的码农 2009-04-13
  • 打赏
  • 举报
回复
private bool WinRarFunction(string path1)
{
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");
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 " + " zdd.rar " + " " + "C:\\1\\1.txt";
the_Info = " a -ep" + " zdd.rar " + " " + path1;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = path1;//获取或设置要启动的进程的初始目录。
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
// Response.Write("压缩成功");
// if(!the_Process.HasExited)
// the_Process.Dispose();
return true;
}
catch (Exception ex)
{
Response.Write(ex.ToString());

return false;
}
}
Nihn 2009-04-13
  • 打赏
  • 举报
回复
我发现解压后的文件中多了一个.rar的文件(目录是C:\Inetpub\wwwroot\pudong\query),里面是程序的代码,请问这是怎么回事?
wuyq11 2009-04-13
  • 打赏
  • 举报
回复
通过GZipStream或SharpZipLib都可实现
参考
Nihn 2009-04-13
  • 打赏
  • 举报
回复
补充,或者没有目录,解压后直接就是文件也可以。
Nihn 2009-04-13
  • 打赏
  • 举报
回复
我试了3楼的办法,但是发现一个问题:例如C:\Inetpub\wwwroot\pudong\images\120001200904071611282下的文件都压成test.rar了,但是解压时,所有的目录(即C:\Inetpub\wwwroot\pudong\images\120001200904071611282)都会出现,而我只希望有120001200904071611282这一层目录。
请大家再探讨一下。
谢谢!
losingrose 2009-04-13
  • 打赏
  • 举报
回复
ICSharpCode.SharpZipLib.dll
支持文件夹压缩

*****************************************************************************
河南地区求职.net程序开发,底薪3000低于勿扰。
欢迎长期技术学习交流朋友,尽力组建一只技术研究的网络团体,研发资料大家共享不外放,新手勿扰。
工作QQ:303864496
http://losingrose.cnblogs.com/
gosling 2009-04-13
  • 打赏
  • 举报
回复
还有可以换一种思路,通过服务器的rar.exe(必须装一个winrar,相信这软件应该是机器基配了)命令实现!
losingrose 2009-04-13
  • 打赏
  • 举报
回复
ICSharpCode.SharpZipLib.dll
支持文件夹压缩

*****************************************************************************
河南地区求职.net程序开发,底薪3000低于勿扰。
欢迎长期技术学习交流朋友,尽力组建一只技术研究的网络团体,研发资料大家共享不外放,新手勿扰。
工作QQ:303864496
http://losingrose.cnblogs.com/
dl_wang 2009-04-13
  • 打赏
  • 举报
回复
up

62,046

社区成员

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

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

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

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