简体   繁体   English

mscorlib.dll中发生类型'System.IO.IOException'的异常,但未在用户代码中处理。 目录名称无效

[英]An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code. The directory name is invalid

I've been trying to upload and import csv file into my datatable but it keeps coming out an error. 我一直在尝试上传csv文件并将其导入到我的数据表中,但它总是出现错误。 It states that the directory name is invalid. 它指出目录名称无效。

    protected void Upload(object sender, System.EventArgs e)
    {

        const string CSV_CONNECTIONSTRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"{0}\";Extended Properties=\"text;HDR=YES;FMT=Delimited\"";

        string csvPath = Server.MapPath("~/Files1/") + Path.GetFileName(FileUpload1.PostedFile.FileName);
        FileUpload1.SaveAs(csvPath);


        **var AllFiles = new DirectoryInfo(csvPath).GetFiles("*csv"); - error here**
string csvPath = Server.MapPath("~/Files1/") + Path.GetFileName(FileUpload1.PostedFile.FileName);

csvPath is file path not directory path. csvPath是文件路径而不是目录路径。

Make sure there is a folder named "File1" in the project root directory. 确保项目根目录中有一个名为“ File1”的文件夹。

and.. 和..

    string csvPath = Server.MapPath("~/Files1/");
    string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
    FileUpload1.SaveAs(Path.Combine(csvPath,fileName));
    var AllFiles = new DirectoryInfo(csvPath).GetFiles("*csv");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mscorlib.dll中发生类型为'System.IO.IOException'的未处理异常目录名称无效 - An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll The directory name is invalid Directory.getFiles mscorlib.dll中发生了类型为'System.IO.IOException'的异常 - Directory.getFiles An exception of type 'System.IO.IOException' occurred in mscorlib.dll 我该如何解决? “ mscorlib.dll中发生了'System.IO.IOException'类型的第一次机会异常” - How can I solve this? “A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll” 使用ZipFile压缩:mscorlib.dll中发生了类型为'System.IO.IOException'的未处理异常 - Using ZipFile compression: An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll 每当我尝试使用此方法时,“ mscorlib.dll中出现类型'System.IO.IOException'的未处理的异常” - “An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll” whenever I try using this method 错误“mscorlib.dll中发生了'System.IO.IOException'类型的未处理异常” - Error “An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll” 错误“ mscorlib.dll中发生了'System.IO.IOException'类型的未处理的异常” - Error “An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll” File.Copy,mscorlib.dll中发生类型为'System.IO.IOException'的未处理异常 - File.Copy, An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll mscorlib.dll中发生类型为'System.IO.IOException'的第一次机会异常 - A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll 为什么会发生“在mscorlib.dll中被类型为'System.IO.IOException'的未处理异常(被某些.exe锁定)”的原因? - why does “An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll (locked by some .exe)” Occur?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM