第一种方式:
最简单的就是返回一个file类型的数据即FilePathResult类型的对象

             string serverPath = ConfigurationManager.AppSettings["file.disk.path"];
             string name = Path.GetFileName(path);
             return File(serverPath + path, mime, name);

第二种方式:

            string serverPath = ConfigurationManager.AppSettings["file.disk.path"];

            FileInfo file = new FileInfo(serverPath + path);
            if (file.Exists)
            {
                Response.ClearContent();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = "text/plain";
                Response.TransmitFile(file.FullName);
                Response.End();
            }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-08-18
  • 2021-05-21
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2021-11-06
  • 2021-07-18
  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
相关资源
相似解决方案