ASP.NET-文件名包含斜杠/时下载文件

时间:2020-07-22 02:29:46

标签: asp.net http url

我正在尝试下载文件名,其中文件名包含格式为dd / MM / yyyy的日期(例如,预期的文件名为MyFile-22/07 / 2020.pdf),但是下载的文件变为MyFile- 22_07_2020.pdf。

下面是我的代码

var filename = Server.UrlDecode("MyFile -" + DateTime.Now.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) + ".pdf"); //which shows MyFile - 22%2f07%2f2020.pdf in debugger
Response.AppendHeader("content-disposition", "attachment; filename=" + filename);
return File(stream, "application/pdf");

如何修改以获得所需的格式?

1 个答案:

答案 0 :(得分:1)

无法在文件名中使用正斜杠,因为/表示您正在引用目录。尝试使用其他字符,或使用看起来像斜杠但不是的Unicode字符。

相关问题