我似乎无法使用下面的连接字符串来读取.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