if (ds.Tables[0].Rows.Count > 0) { byte[] buffer = new byte[4096]; // the path on the server where the temp file will be created! string tempFileName = Server.MapPath(@"1/" + Guid.NewGuid().ToString() + ".zip"); ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create(tempFileName)); string filePath = String.Empty; string fileName = String.Empty; int readBytes = 0; foreach (DataRow dr in ds.Tables[0].Rows) { filePath = Convert.ToString(dr["EvidencePath"]); fileName = Convert.ToString(dr["FilesName"]); ZipEntry zipEntry = new ZipEntry(fileName); zipOutputStream.PutNextEntry(zipEntry); using (FileStream fs = File.OpenRead(filePath)) { do { readBytes = fs.Read(buffer, 0, buffer.Length); zipOutputStream.Write(buffer, 0, readBytes); } while (readBytes > 0); } } if (zipOutputStream.Length == 0) { return; } zipOutputStream.Finish(); zipOutputStream.Close(); Response.ContentType = "application/x-zip-compressed"; Response.AppendHeader("Content-Disposition", "attachment; filename=YourFile.zip"); Response.WriteFile(tempFileName); Response.Flush(); Response.Close(); // delete the temp file if (File.Exists(tempFileName)) File.Delete(tempFileName); //} }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)