我似乎無法使用下面的連接字符串來讀取.csv文件:C#閱讀csv文件給出了不是有效的路徑
var fileName = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Uploads\\countrylist.csv");
string connectionString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=""text;HDR=YES;FMT=Delimited""", fileName);
OleDbConnection oledbConn = new OleDbConnection(connectionString);
oledbConn.Open();
它提供了以下錯誤:
'D:\arrgh\arrgh\Uploads\countrylist.csv' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
我驗證該文件在那裏。這裏發生了什麼?
另請注意,如果您使用Microsoft Jet OLEDB驅動程序讀取CSV文件,則無法讀取其文件名中具有多個點的任何CSV文件。也就是說,「filename.csv」將起作用,但「file.name.csv」不會。 – 2009-09-22 05:36:05
並注意你想使用'sql = SELECT * FROM myfile.csv'(即沒有路徑的文件名)。您可以使用'csvFile = Right(csvPath,Len(csvPath) - InStrRev(csvPath,「\」))' – 2011-10-13 02:31:35
@ TommyO'Dell或簡單地'Path.GetFileName(csvPath)' – 2013-04-05 19:59:01