![](/img/trans.png)
[英]An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll The directory name is invalid
[英]An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code. The directory name is invalid
我一直在尝试上传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**
string csvPath = Server.MapPath("~/Files1/") + Path.GetFileName(FileUpload1.PostedFile.FileName);
csvPath是文件路径而不是目录路径。
确保项目根目录中有一个名为“ File1”的文件夹。
和..
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.