今天分享下昨天做的一个东西 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. Spring入门(3)-Spring命名空间与Bean作用域

    Spring入门(3)-Spring命名空间与Bean作用域 这篇文章主要介绍Spring的命名空间和Bean作用域 0. 目录 Spring命名空间 Bean作用域 1. Spring命名空间 在前 ...

  2. codeforces 617BChocolate

    B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  3. HDU1856More is better(并查集)

    最近发现以前的东西都忘得差不多了,在这里刷刷水题 并查集: int find_parent(int x) { return x = p[x] ? x : p[x] = find_parent(p[x] ...

  4. java tools: jstack

    SYNOPSIS jstack [ option ] pidclick here to see other detail If the given process is running on a 64 ...

  5. CodeForces 732B Cormen — The Best Friend Of a Man (贪心)

    题意:给定n和k表示,狗要在任意连续两天散步次数要至少为k,然后就是n个数,表示每天的时间,让你增加最少次数使得这个条件成立. 析:贪心,策略是从开始到最后暴力,每次和前面一个相比,如果相加不够k,那 ...

  6. Unity3D之Mecanim动画系统学习笔记(十):Mecanim动画的资源加载相关

    资源加载是必备的知识点,这里就说说Mecanim动画的资源如何打包及加载. 注意,Unity4.x和Unity5.x的AssetBundle打包策略不一样,本笔记是基于Unity4.x的AssetBu ...

  7. Oracle DataGuard 物理Standby 搭建(下)

    主备库切换 Switchover 一般SWITCHOVER切换都是计划中的切换,特点是在切换后,不会丢失任何的数据,而且这个过程是可逆的,整个DATA GUARD环境不会被破坏,原来DATA GUAR ...

  8. Codeforces Round #331 (Div. 2)C. Wilbur and Points 贪心

    C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...

  9. memcpy的用法总结

    1.memcpy 函数用于 把资源内存(src所指向的内存区域) 拷贝到目标内存(dest所指向的内存区域):拷贝多少个?有一个size变量控制拷贝的字节数:函数原型:void *memcpy(voi ...

  10. F5 负载均衡

    http://xjsunjie.blog.51cto.com/blog/999372/697285 http://www.eimhe.com/thread-142659-1-1.html