• 文件打包下载


    文件打包器下载地址:http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=dotnetzip&DownloadId=258012&FileTime=129571576121970000&Build=19153

    <!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 id="Head1" 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="&lt;input type=&quot;checkbox&quot;/&gt;" 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("Name") %>'></asp:Label>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </form>
    </body>
    </html>

    using System;
    using System.Collections.Generic;
    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)
    {
    // Server.MapPath("~/upfile/");
    zip.AddFile("d:\\webroot\\" + (gvr.Cells[1].Controls[1] as Label).Text, "");
    }
    }

    zip.Save(Response.OutputStream);
    }

    Response.End();
    }
    }

  • 相关阅读:
    23种设计模式
    doraemon的python Flask框架 websocket和redis
    doraemon的python Flask框架 路由和配置
    doraemon的python Flask框架 安装以及基础应用
    doraemon的python centos的入门(五)用户和用户组权限
    doraemon的python centos的入门(四)查询和压缩文件、文件夹
    doraemon的python centos的入门(三)vim
    doraemon的python centos的入门(二)文件目录操作
    doraemon的python centos的入门(一)增删改查命令
    doraemon的python CRM项目中公户与私户转换、搜索条件的应用
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/2590506.html
Copyright © 2020-2023  润新知