2017-04-09 18 views
0

我試圖用System.Web.HttpContext.Current.Response使用下面的代碼來下載文件:ASP.net下載文件使用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 

有什麼辦法代碼/編碼的文件名,以保持逗號和點?

+0

你爲什麼編碼文件名?它不是一個URI。 –

回答

0

例如,你可以使用:

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