I am able to create a zip with no problem, the only thing I cannot do, stock the zip file in a link so that when the user clicks on the link it will download the file
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=Photo.zip");
using (ZipFile zip = new ZipFile())
{
foreach (var pictures in pictureList)
{
zip.AddFile(Server.MapPath("~\\Content\\pictures\\upload\\" + pictures.name),"images");
}
zip.Save(Response.OutputStream);
}
Response.End();
Code below works for the file downloading.
public void DownloadFile(string fileName)
{
FileInfo file = new FileInfo(@"D:\DOCS\"+fileName);
Context.Response.Clear();
Context.Response.ClearHeaders();
Context.Response.ClearContent();
Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Context.Response.AddHeader("Content-Length", file.Length.ToString());
Context.Response.ContentType = "application/zip";
Context.Response.Flush();
Context.Response.TransmitFile(file.FullName);
Context.Response.End();
}
However, Calling Response.Redirect after Response.End() will not going to work. If you really want to redirect the page you might have to think of an alternative way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.