Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void DownloadSelectedFiles_Click(object sender, EventArgs e)
- {
- string path = String.Empty;
- string zipFilePath = @"C:MyZipFile.zip";
- ZipOutputStream zipStream = new ZipOutputStream(File.Create(zipFilePath));
- byte[] buffer = new byte[4096];
- foreach (GridViewRow row in gvFiles.Rows)
- {
- bool isSelected = (row.FindControl("chkSelect") as CheckBox).Checked;
- if (isSelected)
- {
- path = (row.FindControl("lblUrl") as Label).Text;
- ZipEntry entry = new ZipEntry(Path.GetFileName(path));
- entry.DateTime = DateTime.Now;
- zipStream.PutNextEntry(entry);
- using (FileStream fs = File.OpenRead(path))
- {
- int sourceBytes;
- do
- {
- sourceBytes = fs.Read(buffer, 0, buffer.Length);
- zipStream.Write(buffer, 0, sourceBytes);
- } while (sourceBytes > 0);
- }
- }
- }
- zipStream.Finish();
- zipStream.Close();
- Response.ContentType = "application/x-zip-compressed";
- Response.AppendHeader("Content-Disposition", "attachment; filename=SS.zip");
- Response.WriteFile(zipFilePath);
- Response.End();
- }
- Response.Buffer = true;
- Response.Clear();
- Response.ClearContent();
- Response.ClearHeaders();
- Response.Flush()
- Response.Close()
- Response.Buffer = true;
- Response.Clear();
- Response.ClearContent();
- Response.ClearHeaders();
- Response.ContentType = "application/x-zip-compressed";
- Response.AppendHeader("Content-Disposition", "attachment; filename=SS.zip");
- Response.WriteFile(zipFilePath);
- Response.Flush()
- Response.Close()
- Response.End();
Add Comment
Please, Sign In to add comment