文件下载文件名兼容中英文空格

//下载
        string filePath = Server.MapPath("../Temp/" + ofname);//路径
        FileInfo fileInfo = new FileInfo(filePath);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AppendHeader("Content-Disposition", "attachment; filename="" + Server.UrlEncode(ofname) + """);//防止中文名出乱码,不过文件名中的空格会被“+”代替
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding", "binary");
        Response.ContentType = "application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();

原文地址:https://www.cnblogs.com/yubufan/p/3559727.html