[英]How to resolve the exception System.IO.IOException: 'the filename, directory name, or volume label syntax is incorrect in C#?
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);
}
I get an exception on filebytes1 and I'm wondering how to resolve the issue.我在 filebytes1 上遇到异常,我想知道如何解决该问题。 I have parameter called downloaddate which is a calendar date picker in HTML. Every time I pick a date and click the button, I get an exception System.IO.IOException: 'the filename, directory name, or volume label syntax is incorrect.
我有一个名为 downloaddate 的参数,它是 HTML 中的一个日历日期选择器。每次我选择一个日期并单击该按钮时,我都会收到一个异常 System.IO.IOException: '文件名、目录名或卷 label 语法不正确。 How can I resolve this issue?
我该如何解决这个问题?
I created a variable called Date and set is as a New DateTime.我创建了一个名为 Date 的变量并将其设置为新的 DateTime。 Then, referenced the variable Date to downloaddate parameter.
然后,将变量 Date 引用到 downloaddate 参数。
Here's the code:这是代码:
DateTime Date = new DateTime();
Date = (DateTime)downloaddate;
string path1 = AppDomain.CurrentDomain.BaseDirectory + "logs/";
string filename = "industrialcomm-payload-" + Date.ToString("yyyyMMdd") + ".log";
byte[] filebytes1 = System.IO.File.ReadAllBytes(path1 + filename);
string contentType1 = "text/plain";
return File(filebytes1, contentType1, filename);
This will set the calender downloaddate to DateTime().这会将日历下载日期设置为 DateTime()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.