I'm trying to force the browser to download a zip file. I have read lots of posts about the same problem with many accepted answers. Still I can't make it to work. Below is the code I have written.
var Response = _context.Response;
string contentDisposition = string.Format("attachment; filename=data.zip");
string contentLength;
using (FileStream fileStream = File.OpenRead(_context.Server.MapPath(@"~/csv/data.zip")))
{
contentLength = fileStream.Length.ToString(System.Globalization.CultureInfo.InvariantCulture);
}
Response.AddHeader("Content-Type", "application/force-download;");
Response.AddHeader("Content-Disposition", contentDisposition);
Response.AddHeader("Content-Length", contentLength);
Response.AddHeader("Content-Description", "File Transfer");
Response.AddHeader("Content-Transfer-Encoding", "binary");
//Response.TransmitFile(_context.Server.MapPath(@"~/csv/data.zip"));
Response.WriteFile(_context.Server.MapPath(@"~/csv/data.zip"));
Response.Flush();
Response.End();
The zip is not downloaded. I just see the response .
Headers