C# 下载文件 只利用文件的存放路径来下载


第一种方式:
最简单的就是返回一个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();
            }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM