Introduction
In this article I explain how to bind files in a GridView and how to download selected files in zip format.
Requirements
The requirements are:
- Dll Ionic.Zip.dll
- The following namespace:
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Web.UI.WebControls;
- using Ionic.Zip;
Add the Ionic.Zip.dll to your bin folder of the application then add the namespaces above.
Code .aspx :
I have some files in my application, file1.txt and file2.doc. I bind these files in the GridView. But before binding to the GridView I design my page. Use the following code to understand what I have done :
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Download in zip format</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <br />
- <asp:Label ID="lbl_txt" runat="server" Font-Bold="true" ForeColor="Red" />
- </div>
- <asp:GridView ID="gridview1" CellPadding="5" runat="server" AutoGenerateColumns="false">
- <Columns>
- <asp:TemplateField>
- <ItemTemplate>
- <asp:CheckBox ID="chk_Select" runat="server" />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:BoundField DataField="Text" HeaderText="FileName" />
- </Columns>
- <HeaderStyle BackColor="white" Font-Bold="true" ForeColor="White" />
- </asp:GridView>
- <asp:Button ID="btn_Download" Text="Download " runat="server" OnClick="btnDownload_Click" />
- </form>
- </body>
- </html>

Hamid KhanPosted Mar 9, 2021, 11:01 AM
Good explanation...........
sherry shairPosted Mar 28, 2014, 6:31 AM
good
Saineshwar BageriPosted Feb 20, 2014, 11:38 PM
Nice one