简体   繁体   English

如何解决异常System.IO.IOException: 'the filename, directory name, or volume label syntax is incorrect in C#?

[英]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.

相关问题 C#OpenFileDialog:文件名,目录名称或卷标签语法不正确 - C# OpenFileDialog: The filename, directory name, or volume label syntax is incorrect 文件名、目录名或卷 label 语法不正确,c# - The filename, directory name, or volume label syntax is incorrect, c# 如何修复System.Net.WebException:'文件名,目录名或卷标签语法不正确 - How do I fix System.Net.WebException: 'The filename, directory name, or volume label syntax is incorrect C#-System.IO.IOException - C# - System.IO.IOException 文件名,目录名称或卷标签语法不正确。 (来自HRESULT的异常:0x8007007B) - The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B) File.Copy错误-C#-IOException文件名,目录名或卷标签 - File.Copy error - C# - IOException The filename, directory name, or volume label windres:文件名,目录名或卷标签语法不正确 - windres: The filename, directory name, or volume label syntax is incorrect 文件流 - 文件名、目录名或卷 label 语法不正确 - Filestream - The filename, directory name, or volume label syntax is incorrect 文件名,目录名或卷标语法不正确,File.Copy - The filename, directory name, or volume label syntax is incorrect, File.Copy mscorlib.dll中发生类型为'System.IO.IOException'的未处理异常目录名称无效 - An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll The directory name is invalid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM