[英]how to create zip and stock it in a link MVC or provide zip to user and redirect
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 我能够毫无问题地创建一个zip文件,唯一不能做的就是将zip文件存储在链接中,以便用户单击链接时它将下载文件。
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. 但是,在Response.End()之后调用Response.Redirect将无法工作。 If you really want to redirect the page you might have to think of an alternative way.
如果您确实要重定向页面,则可能不得不考虑另一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.