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

  • 相关阅读:
    LightOJ 1300 边双联通分量+交错路染色
    HDU 6143 快速幂,组合数
    windows 下fc工具
    HDU 6136 模拟
    HDU 6129 暴力,规律
    UVA Live 7770 模拟
    1096: [ZJOI2007]仓库建设
    1191: [HNOI2006]超级英雄Hero
    3224: Tyvj 1728 普通平衡树
    1208: [HNOI2004]宠物收养所
  • 原文地址:https://www.cnblogs.com/soundcode/p/5098918.html
Copyright © 2020-2023  润新知