【发布时间】:2021-12-30 15:13:30
【问题描述】:
public ActionResult Download(DateTime? downloaddate)
{
{
string path1 = AppDomain.CurrentDomain.BaseDirectory + "logs/";
string filename = "industrialcomm-payload-" + downloaddate + ".txt";
byte[] filebytes1 = System.IO.File.ReadAllBytes(path1 + filename);
string contentType1 = "text/plain";
return File(filebytes1, contentType1);
}
我在 filebytes1 上遇到异常,我想知道如何解决这个问题。我有一个名为 downloaddate 的参数,它是 HTML 中的日历日期选择器。每次我选择一个日期并单击按钮时,我都会收到异常 System.IO.IOException: 'the filename, directory name, or volume label syntax is wrong.我该如何解决这个问题?
【问题讨论】:
-
你有没有在运行时检查过“path1 + filename”的值是什么?
-
DateTime将包含/字符,这些字符对于文件名不安全。我希望您需要格式化日期以匹配文件名的实际名称。 -
@burcinsahin 是的,我做到了,并且路径与文件位置匹配。
标签: c# datetime exception filepath