zoukankan      html  css  js  c++  java
  • MVC 服务器文件下载

    文件上传到服务器后下载

    window.open   与window.location.href  对txt  或是pdf文件执行的操作是打开,而非下载

    mvc controller 自带有如下方法


    protected internal FileContentResult File(byte[] fileContents, string contentType);
    protected internal FileStreamResult File(Stream fileStream, string contentType);
    protected internal FilePathResult File(string fileName, string contentType);
    protected internal virtual FileContentResult File(byte[] fileContents, string contentType, string fileDownloadName);
    protected internal virtual FileStreamResult File(Stream fileStream, string contentType, string fileDownloadName);
    //
    // 摘要:
    // 使用文件名、内容类型和文件下载名创建一个 System.Web.Mvc.FilePathResult 对象。
    //
    // 参数:
    // fileName:
    // 要发送到响应的文件的路径。
    //
    // contentType:
    // 内容类型(MIME 类型)。
    //
    // fileDownloadName:
    // 浏览器中显示的文件下载对话框内要使用的文件名。
    //
    // 返回结果:
    // 文件流结果对象。
    protected internal virtual FilePathResult File(string fileName, string contentType, string fileDownloadName);

    调用以上方法,即可对任何类型文件进行下载,并可以重命名

    public ActionResult DownLoad(string path)
    {
        return File(path, "", "重命名.txt");
    }

  • 相关阅读:
    17.正则表达式
    16.os模块-shutil模块-tarfile压缩模块
    15.序列化模块-时间模块-zip压缩模块
    第一章 单变量线性回归
    如何跑通MonoRTM模型的官方例子
    PHP命名规范
    js中要声明变量吗?
    php抓取网站图片源码
    InnoDB和MyISAM区别总结
    php分页代码。
  • 原文地址:https://www.cnblogs.com/soundcode/p/5098918.html
Copyright © 2011-2022 走看看