In MVC, instead of returning a view, if you want to return a file, you can return it as ActionResultby doing:
return File(zipFile.GetBytes(), "application/zip", downloadFileName);
return File(zipFile.GetStream(), "application/zip", downloadFileName);
Do not argue with manual recording in the output stream if you use MVC.
, ZipFile. , MemoryStream :
var cd = new System.Net.Mime.ContentDisposition {
FileName = downloadFileName,
Inline = false,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
var memStream = new MemoryStream();
zipFile.Save(memStream);
memStream.Position = 0;
return File(memStream, "application/zip");
, , - Response. Clear AddHeader.