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");
    }

  • 相关阅读:
    git 项目代码打包
    jira查看字段
    jmeter压力测试报错:java.net.BindException: Address already in use: connect解决办法
    python 破解验证码
    mysql授权远程登录
    豆瓣api
    利用python开发财务工具
    钉钉发送消息通知
    git使用命令行自动登录
    后宫
  • 原文地址:https://www.cnblogs.com/soundcode/p/5098918.html
Copyright © 2011-2022 走看看