今天分享下昨天做的一个东西 asp.net 的文件  zip 批量下载,首先你需要去 到http://dotnetzip.codeplex.com这个站点下载zip 的包,在里面找到 Ionic.Zip.dll  引用到你的项目中去

 /// <summary>
/// 批量zip下载
/// </summary>
/// <param name="Listimg">这里Listimg 是一个数组类型</param>
public void CreateZip(string Listimg)
{
string[] imgs = Listimg.Split(',');
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BufferOutput = false; //网站文件生成一个readme.txt的自述文件(可以不写)
String readmeText = String.Format("README.TXT" +Environment.NewLine+"网址址:http://www.aicoffees.com" ); HttpContext.Current.Response.ContentType = "application/zip";//以zip 形式输出
HttpContext.Current.Response.AddHeader("content-disposition", "inline; filename=\"Photo.zip");//压缩下载的名字 //批量压缩操作
using (ZipFile zip = new ZipFile())
{
for (int i = ; i < imgs.Length; i++)
{ ///在压缩包内添加上面的自述文件,文字编码是系统默认编码形式 zip.AddEntry("Readme.txt", readmeText, Encoding.Default); zip.Password = "www.aicoffees.com";//给压缩包设置密码
zip.Encryption = EncryptionAlgorithm.WinZipAes256;//加密方式 zip.AddFile(HttpContext.Current.Server.MapPath(imgs[i].ToString()), "");//这里"" 我给的是空就是压缩时不设置文件夹,如果需要取什么名字只需要在“”里面加上就可以了,这里是一个重载方法,如果 zip.AddFile(HttpContext.Current.Server.MapPath(imgs[i].ToString()), "");这样写的话,zip 就会默认把你的image从根目录一直压缩到你的文件所在目录。 }
zip.Save(HttpContext.Current.Response.OutputStream); }
HttpContext.Current.Response.Close(); }

以上是自己的一点小总结,come on

asp.net 文件压缩zip下载的更多相关文章

  1. asp.net文件压缩,下载,物理路径,相对路径,删除文件

    知识动手实践一次,就可以变成自己的了.不然一直是老师的,书本的. 这几天做了一个小小的项目,需要用到文件下载功能,期初想到只是单个的文件,后面想到如果很多文件怎么办?于是又想到文件压缩.几经波折实践, ...

  2. javaweb通过接口来实现多个文件压缩和下载(包括单文件下载,多文件批量下载)

    原博客地址:https://blog.csdn.net/weixin_37766296/article/details/80044000 将多个文件压缩并下载下来:(绿色为修改原博客的位置) 注意:需 ...

  3. 分享一个ASP.NET 文件压缩解压类 C#

    需要引用一个ICSharpCode.SharpZipLib.dll using System; using System.Collections.Generic; using System.Linq; ...

  4. Web端文件打包.zip下载

    使用ant.jar包的API进行文件夹打包.直接上代码: String zipfilename = "test.zip"; File zipfile = new File(zipf ...

  5. php 文件压缩zip扩展

    <?php function addFileToZip($path, $zip) { $handler = opendir($path); //打开当前文件夹由$path指定. while (( ...

  6. asp.net文件上传下载组件

    以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载. 准备文件上传的API #region 文件上传  ...

  7. asp.net文件上传下载

    泽优大文件上传产品测试 泽优大文件上传控件up6,基于php开发环境测试. 开发环境:HBuilder 服务器:wamp64 数据库:mysql 可视化数据库编辑工具:Navicat Premium ...

  8. 下载zip格式文件(压缩Excel文件为zip格式)

    Mongodb配置文件参考这一篇:http://www.cnblogs.com/byteworld/p/5913061.html package util; import java.io.Buffer ...

  9. php多文件压缩下载

    /*php多文件压缩并且下载*/ function addFileToZip($path,$zip){ $handler=opendir($path); //打开当前文件夹由$path指定. whil ...

随机推荐

  1. 从工程中删除Cocoapods

    从工程中删除Cocoapods 分类: Xcode iOS 2013-08-24 01:11 5512人阅读 评论(2) 收藏 举报 CocoapodsiOSXcode 1. 删除工程文件夹下的Pod ...

  2. AVCaptureDevice

    转载自:http://blog.csdn.net/andy_jiangbin/article/details/19820717   0.媒体采集的几个东西.这里所需要明白的是,在这个流程中,这里会存在 ...

  3. linux知识积累

                                                         linux 操作系统一.linux 操作系统概述   简介            Linux是 ...

  4. 【转】Watir, Selenium & WebDriver

    转自:http://watirmelon.com/2010/04/10/watir-selenium-webdriver/ Please also see my new ‘Watir-WebDrive ...

  5. [AngularJS] Introduction to ui-router

    Introduce to basic $stateProvider.state() with $stateParams services. Understand how nested router w ...

  6. perl详解

    http://www.blogjava.net/qileilove/archive/2013/09/04/403646.html

  7. debian分区方案(就这个看着靠谱点)转

    debian分区方案(就这个看着靠谱点)转 桌面系统/tmp 1G (仅用作临时文件) ext3/ext4/home Max (用户目录数据) ext3/ext4/usr 20G (软件) ext3/ ...

  8. discuz pc端显示触摸版

    1./source/function/function_core.php function checkmobile() {return true; //此为加上的内容global $_G; ..... ...

  9. Skip list--reference wiki

    In computer science, a skip list is a data structure that allows fast search within an ordered seque ...

  10. 有符号的范围,-128~+127详解(zt)

    这是一个困惑了我几年的问题,它让我对现在的教科书和老师极其不满,从我N年前开始摸电脑时,就几乎在每一本C++教科书上都说,8位有符号的取值范围是-128~+127,为什么不是-127~+127呢,后来 ...