今天分享下昨天做的一个东西 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. HDU 2425 DNA repair (AC自动机+DP)

    DNA repair Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. Spring Data JPA教程, 第七部分: Pagination(未翻译)

    The previous part of my Spring Data JPA tutorialdescribed how you can sort query results with Spring ...

  3. iOS 通知中心 NSNotificationCenter

    iOS开发中,每个app都有一个通知中心,通知中心可以发送和接收通知. 在使用通知中心 NSNotificationCenter之前,先了解一下通知 NSNotification. NSNotific ...

  4. sql:[dbo].[smt_MES_RptProductDaily] 生产日报表

    USE [ChangHongMES_904]GO/****** Object: StoredProcedure [dbo].[smt_MES_RptProductDaily] Script Date: ...

  5. synthesize(合成) keyword in IOS

    synthesize creates setter and getter (从Objective-C 2.0开始,合成可自动生成存取方法) the setter is used by IOS to s ...

  6. C#实现注销、重启和关机代码

    首先要导入对命名空间 using System.Runtime.InteropServices; 的引用 [StructLayout(LayoutKind.Sequential, Pack = 1)] ...

  7. [Angular 2] Understanding Pure & Impure pipe

    First, how to use a build in pipe: <div class="pipe-example"> <label>Uppercase ...

  8. [GIF] The Phase Property in GIF Loop Coder

    In this lesson, we look at one of the most powerful features in GIF Loop Coder, the phase property, ...

  9. [AngularJS] Lazy loading Angular modules with ocLazyLoad

    With the ocLazyLoad you can load AngularJS modules on demand. This is very handy for runtime loading ...

  10. Android Bundle传递简单数据、对象数据

    Android开发过程中进程遇到组件之间.进程之间等数据的传递,数据传递有非常多种,当中使用Bundle传递非常方便. Bundle能够传递多种数据,是一种类似map的key-value数据结构 简单 ...