C# 使用HttpContext.Current.Response文件名下载ASP.net文件
我正在尝试使用以下代码使用System.Web.HttpContext.Current.Response下载文件:C# 使用HttpContext.Current.Response文件名下载ASP.net文件,c#,asp.net,httprequest,httpresponse,html-encode,C#,Asp.net,Httprequest,Httpresponse,Html Encode,我正在尝试使用以下代码使用System.Web.HttpContext.Current.Response下载文件: HttpResponse objResponse = System.Web.HttpContext.Current.Response; 我正在使用以下代码对文件名进行编码: FileName = Uri.EscapeDataString(FileName); 文件正在正确下载,除非文件名中有逗号或点 在这种情况下,在下载文件时,资源管理器无法将逗号解码回来 例如: Origin
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
有没有办法对文件名进行编码,以保留逗号和点 例如,您可以使用:
public ActionResult DownloadFileXML(string filePath)
{
string fileName = Path.GetFileName(filePath);
return File(filePath, "application/xml", fileName);
}
为什么要对文件名进行编码?它不是URI。