【问题标题】:ASP.net download file Using HttpContext.Current.Response fileNameASP.net 下载文件使用 HttpContext.Current.Response 文件名
【发布时间】:2017-04-09 15:09:57
【问题描述】:

我正在尝试使用 System.Web.HttpContext.Current.Response 使用以下代码下载文件:

HttpResponse objResponse = System.Web.HttpContext.Current.Response;

我正在使用以下代码对文件名进行编码:

FileName = Uri.EscapeDataString(FileName);

文件正在正确下载,除非文件名中有逗号或点。

在这种情况下,在下载文件时,资源管理器无法将逗号解码。

例如:

Original file name: Testing, File
Encoded name: Testing%2C%20file
Downloaded file name:  Testing%2C file

有没有办法对文件名进行编码/编码,以保留逗号和点?

【问题讨论】:

  • 为什么要对文件名进行编码?它不是一个 URI。

标签: c# asp.net httprequest httpresponse html-encode


【解决方案1】:

例如,您可以使用:

public ActionResult DownloadFileXML(string filePath)
{
string fileName = Path.GetFileName(filePath);
return File(filePath, "application/xml", fileName);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多