Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Download multiple files as Zip Archive File using GridView in ASP.Net

Displaying the Files stored in Folder on the Server in ASP.Net GridView

Place GridView control on my Web Page along with a Button that will be used to download the Files.
var Downloadfilename = string.Format("Sheet-{0}{1}.zip",cmf.Decrypt(Request.QueryString["Month"].ToString().Trim()).Replace(" ","").Replace(":",""), "-" + DateTime.Now.ToString("yyyy-MM-dd-HH_mm_ss"));
        try
        {
            Response.Clear();
            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadFileName);
            // Zip the contents of the selected files
            using (var zip = new ZipFile())
            {
                // Add the password protection, if specified
                // Construct the contents of the README.txt file that will be Included in this ZIP
                var Readmemessage = string.Format("Your ZIP file {0} contains the following files:{1}{1}", downloadFileName, Environment.NewLine);

                // Add the checked files to the ZIP
                foreach (ListItem li in chkDownloadFileData.Items)
                    if (li.Selected)
                    {
                        // Record the file that was included in readMeMessage
                        readMeMessage += string.Concat("\t* ", li.Text, Environment.NewLine);

                        // Now add the file to the ZIP (use a value of "" as the second parameter to put the files in the "root" folder)
                        zip.AddFile(li.Value, "Excel Data");
                    }

                // Add the README.txt file to the ZIP
                zip.AddEntry("README.txt", readMeMessage, Encoding.ASCII);

                // Send the contents of the ZIP back to the output stream
                zip.Save(Response.OutputStream);
                Response.End();
            }
        }
        catch { }
        finally { Response.End(); }
    }
    protected virtual void DisplayAlert(string message)
    {
        ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), string.Format("alert('{0}');", message.Replace("'", @"\'")), true);
    }



This post first appeared on Pivot In SQL Server, please read the originial post: here

Share the post

Download multiple files as Zip Archive File using GridView in ASP.Net

×

Subscribe to Pivot In Sql Server

Get updates delivered right to your inbox!

Thank you for your subscription

×