引用:using System.Web.Mvc;

path 可以是相对路径,也可以是绝对路径

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
 public FilePathResult DownloadFile(string path)
        {
            path = path.Replace("\\", "/");
            string type = string.Empty;
            int extIndex = path.LastIndexOf(".");
            if (extIndex > 0)
            {
                type = "application/" + path.Substring(extIndex + 1);
            }

            string name = string.Empty;
            int nameIndex = path.LastIndexOf("/");
            if (nameIndex > 0)
            {
                name = path.Substring(nameIndex + 1);
            }

            return File("~/" + path, "application/" + type, name);
        }

  

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄