Hi all,
Please help me to import
.csv
file sheet name.
string full = Path.GetFullPath(excelFile);
string file = Path.GetFileName(full);
string dir = Path.GetDirectoryName(full);
connString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=\"" + dir + \\";"
+ "Extended Properties=\"text;HDR=No;FMT=Delimited\"";
objConn = new OleDbConnection(connString);
string query = "SELECT * FROM " + file;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
dAdapter.Fill(dTable);
objConn.Open();
dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
As I know for
.csv
extension files in connection string, we cant give file path for data source(as like as
.xls
or
.xlsx
file), instead we need to give the folder path in which uploaded
.csv
exists..
So same I have mentioned...
And I am able to get all uploaded
.csv
file values in
dTable.
But while retrieving sheet names I am unable to pass Uploaded file name because...
To retrieve sheet name of an uploaded file we need to write this line
dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
But here I am passing
objConn
(Which consists datasource as dir )
So,
dt retrieves all files present in that connectionstring dir folder ( in
dt I need to retrieve sheet names present in uploaded
.csv
file ), and all those files are showing as a sheet names.
This is the Issue unable to clear and I need uploaded
.csv
file sheetnames..
How to do that ?
I Google from past 3 days, but I am unable to get the solution.
Please help.
Thanks in advance.