![](/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.