C# 类型为';System.IO.IOException';在mscorlib.dll中发生,但未在用户代码中处理。目录名无效

C# 类型为';System.IO.IOException';在mscorlib.dll中发生,但未在用户代码中处理。目录名无效,c#,asp.net,visual-studio-2015,C#,Asp.net,Visual Studio 2015,我一直试图上传csv文件并将其导入到我的数据表中,但总是出现错误。它声明目录名无效 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=Del

我一直试图上传csv文件并将其导入到我的数据表中,但总是出现错误。它声明目录名无效

    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**
csvPath是文件路径而不是目录路径

确保项目根目录中有一个名为“File1”的文件夹


csvPath
中的值是多少看起来您正在使用文件路径获取目录中的所有文件。那不行。使用新目录信息中“~/Files1/”的路径出现另一个错误。其他信息:找不到路径“C:\Program Files(x86)\IIS Express\~\Files1”的一部分。如何检查路径中的值?哇,谢谢^^但是另一个错误出现在不同的代码中。string ConStr=ConfigurationManager.ConnectionString[“ConStr”].ConnectionString;它表示对象引用未设置为对象的实例。请检查此。。。
string csvPath = Server.MapPath("~/Files1/") + Path.GetFileName(FileUpload1.PostedFile.FileName);
    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");