如何在zip文件中压缩文件夹并下载? [英] How to compress folder in zip file and download?

查看:90
本文介绍了如何在zip文件中压缩文件夹并下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



希望做得好,



i我在文件夹中有一个子文件夹服务器我想压缩和下载。



这里是我的代码:



Hi all,

Hope doing well,

i am having one subfolder in folder in the server which i am trying to compress and download.

here is my code:

string subfol = Session["inbpostedfol"].ToString();
           string fullpath = Server.MapPath("~/InboxFiles/" + subfol);
           FileInfo flie = new FileInfo(fullpath);
           Response.Clear();
           Response.ContentType = "application/zip";
           Response.AddHeader("content-disposition", "attachment; filename=" + subfol + ".zip");
           using (ZipFile zipfile = new ZipFile())
           {
               zipfile.AddSelectedFiles("*.*", subfol, fullpath);
               zipfile.Save(Response.OutputStream);
           }





但是没有将文件放在压缩文件夹中。



谢谢



but not getting the file in compressed folder.

thanks

推荐答案

使用 ZipFile.CreateFromDirectory方法 [ ^ ]到一个临时文件中,然后以通常的方式将文件发送到您的客户端。然后,您可以在您之后清理文件。
Use the ZipFile.CreateFromDirectory method[^] into a temporary file, then send the file to your client in your usual way. You can then clean up the file after you.


这篇关于如何在zip文件中压缩文件夹并下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆