I am importing ".xls/.xlsx/.csv" file using switch case and ".xls/.xlsx" works fine but ".csv" file shows me the error as follows
"'*.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."
in
oconn.open()
.
Could someone please help me.
I'm using the following code:
switch (Extension)
{
case ".xls":
conStr = String.Format(ConfigurationManager.ConnectionStrings["WorkingConnectionStringforxls"].ConnectionString + (char)34, path, (char)34);
break;
case ".xlsx":
conStr = String.Format(ConfigurationManager.ConnectionStrings["WorkingConnectionStringforxlsx"].ConnectionString + (char)34, path, (char)34);
break;
case ".csv":
conStr = String.Format(ConfigurationManager.ConnectionStrings["WorkingConnectionStringforcsv"].ConnectionString + (char)34, path, (char)34);
break;
}
oconn = new OleDbConnection(conStr);
oconn.Open();
OleDbCommand ocmd1 = new OleDbCommand("select count(*) from [Sample input sheet$]", oconn);
Int32 count = (Int32)ocmd1.ExecuteScalar();
if (count == 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "errale", "alert('The excel sheet is empty');", true);
}
else
{
GridView1.DataSource = ExtractData();
GridView1.DataBind();
UpdateMaterial.Visible = true;
}
oconn.Close();
This is the connection string I'm using in web.config:
<add name="WorkingConnectionStringforcsv" connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties={1}text;HDR=NO;FMT=Delimited;" />
Thanks in advance.