ASP.NET多文件批量打包下载
在对多文件打包中用到了 DotNetZip 的方法来实现对多文件压缩打包。需要到http://dotnetzip.codeplex.com/处下载该文件,然后引用即可。
Default.aspx:
<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>图片打包下载</title>
</head>
<body>
<form id="form1" runat="server">
<p>
<asp:Button ID="PackDown" runat="server" Text="打包下载" OnClick="PackDown_Click" /></p>
<asp:GridView ID="GridView1" runat="server" Width="500px"
CellPadding="8" CellSpacing="1">
<Columns>
<asp:TemplateField HeaderText="<input type="checkbox"/>" InsertVisible="False">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="文件列表" InsertVisible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# eval_r("Name") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Ionic.Zip;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindFilesList();
}
}
void BindFilesList()
{
List<System.IO.FileInfo> lstFI = new List<System.IO.FileInfo>();
string[] files = System.IO.Directory.GetFiles("d:\\webroot");
foreach (var s in files)
{
lstFI.Add(new System.IO.FileInfo(s));
}
GridView1.DataSource = lstFI;
GridView1.DataBind();
}
protected void PackDown_Click(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=DotNetZip.zip");
using (ZipFile zip = new ZipFile(System.Text.Encoding.Default))//解决中文乱码问题
{
foreach (GridViewRow gvr in GridView1.Rows)
{
if (((CheckBox)gvr.Cells[0].Controls[1]).Checked)
{
zip.AddFile("d:\\webroot\\" + (gvr.Cells[1].Controls[1] as Label).Text, "");
}
}
zip.Save(Response.OutputStream);
}
Response.End();
}
}
ASP.NET多文件批量打包下载的更多相关文章
- 用Spring中的ResponseEntity文件批量压缩下载
我看了很多网上的demo,先生成ZIP压缩文件,然后再下载. 我这里是生成ZIP文件流 进行下载.(核心代码没多少,就是一些业务代码) @RequestMapping(value = "/& ...
- ASP.NET网站文件上传下载功能
if (!IsPostBack) { if (Application["RaNum"] == null) { Random ra = new Random(); Applicati ...
- ASP.NET五步打包下载Zip文件
本文版权归博客园和作者吴双共同所有,转载和爬虫请注明原文地址:www.cnblogs.com/tdws 首先分享几个振奋人心的新闻: 1.谷歌已经宣布加入.NET基金会 2.微软加入Linux基金会, ...
- JavaWeb多文件上传及zip打包下载
项目中经常会使用到文件上传及下载的功能.本篇文章总结场景在JavaWeb环境下,多文件上传及批量打包下载功能,包括前台及后台部分. 首先明确一点: 无法通过页面的无刷新ajax请求,直接发下载.上 ...
- java zip 批量打包(java.util包和apache.tools包)
/** * 文件批量打包 * @param zipPath 打包路径 * @param files 批量文件 */ public void zipOut(String zipPath,File[] f ...
- asp.net怎样实现批量下载文件(非打包形式下载)
问题: 我想实现的是一个一个的下载. 比如我有一个文件列表.通过checkbox选择.通过单击下载按钮下载选中文件. 百度到都是用打包形式实现批量下载. 这是我自己写的代码,但是点击下载后只能下载一个 ...
- ASP.NET 打包下载文件
使用的类库为:ICSharpCode.SharpZipLib.dll 一种是打包整个文件夹,另一种是打包指定的多个文件,大同小异: using ICSharpCode.SharpZipLib.Zip; ...
- asp.net 文件压缩zip下载
今天分享下昨天做的一个东西 asp.net 的文件 zip 批量下载,首先你需要去 到http://dotnetzip.codeplex.com这个站点下载zip 的包,在里面找到 Ionic.Z ...
- Android 自动编译、打包生成apk文件 4 - 多渠道批量打包
相关文章列表: < Android 自动编译.打包生成apk文件 1 - 命令行方式> < Android 自动编译.打包生成apk文件 2 - 使用原生Ant方式 > < ...
随机推荐
- On the first day here
记录一下到这里的第一天 简单的自我介绍一下: 姓名: 郑超杰 昵称: 蝴蝶 English Nickname: developerbfl 技能: OC H5 Swift ...
- ubuntu 安装python mysql模块
Installation Starting with a vanilla Lucid install , install pip and upgrade to the latest version: ...
- phantomjs处理alert、confirm弹窗
一:phantomjs处理alert弹窗 脚本实现功能为:点击click me按钮弹出弹窗消息为cheese,点击确定按钮,弹窗关闭 脚本代码为:注意的是phantomjs处理alert弹窗需要将ph ...
- [JS思路]运动框架思路
匀速运动的思路一: 1.先清除动画,再加载动画 2.方向dir有正值和负值,可以通过 目标值 > 当前值 往右移动,即正数 目标值 < 当前值 往右移动,即负数 来进行判断:dir = ...
- JS复习:第七章
第七章 函数表达式 一.定义函数的方式有两种:函数声明和函数表达式. 1.函数声明: function functionName(arg0 , arg1 , arg2){ //函数体... } 函数 ...
- a标签href跳转---传值---禁止单引号
禁止加单引号1 href传参的值 (&t_type='航班') 错误 <a href="check_apply?applyid=<?=$applyid?>&am ...
- MySQL(3)-索引
一.索引类型 在MySQL中,存储引擎使用索引,首先在索引中找到对应值,然后根据匹配的索引记录中找到对应的行. 无论是多么复杂的ORM工具,在精妙和复杂的索引面前都是"浮云".这里 ...
- wpf ListBox 双击事件时在子项添加Style 确保选中
<ListBox ItemTemplate="{StaticResource CardPictureTemplate}" VirtualizingPanel.CacheLen ...
- javascript焦点图之缓冲滚动无缝切换
在用于实现无缝切换四张图,所以设置了6个图片就是 4,0,1,2,3,4,0 <!DOCTYPE html> <html> <head> <meta char ...
- submit提交表单后,不刷新当前页面
<form method="get" target="test" action="a.html"> <input type ...