强制浏览器下载zip c#

时间:2015-01-14 09:41:03

标签: c# download

我正在尝试强制浏览器下载zip文件。我已经阅读了许多关于同一问题的帖子,其中包含许多已接受的答案我仍然无法使它发挥作用。以下是我编写的代码。

  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();

未下载zip。我只看到了回应。

enter image description here

接头

enter image description here

0 个答案:

没有答案