asp.net实现文件夹及文件压缩,并实现下载

这篇博客介绍了如何在ASP.NET中使用ICSharpCode.SharpZipLib库来压缩文件夹及其内容,并提供了一个实现文件下载的示例。通过Button2_Click事件触发,将指定路径的"D://华海实训(hohisoft.com)各级账号和密码"文件夹压缩为'华海实训(hohisoft.com)服务账号.zip'供用户下载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 步骤

1)先引用 ICSharpCode.SharpZipLib.dll;

2).cs文件引入

using System.IO;
using System.Text;

using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;

 

3)代码

 

 #region 下列代码为压缩并下载代码
       ZipOutputStream zos = null;
       String strBaseDir = "";


       void dlZipDir(string strPath, string strFileName)
       {
           MemoryStream ms = null;
           Response.ContentType = "application/octet-stream";
           strFileName = HttpUtility.UrlEncode(strFileName).Replace('+', ' ');
         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值