Note: I'm using MySql as database. I've also set the permissions to the folder on my server where the file get stored after uploading still the same issue.
if (file_Upload_DataFile.HasFile) { string fileName = Path.GetFileName(file_Upload_DataFile.PostedFile.FileName); string fileExtension = Path.GetExtension(file_Upload_DataFile.PostedFile.FileName); if (fileExtension != ".xls" && fileExtension != ".xlsx") { ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "alert('invalid file format!! you must upload a file having an extention of either (.xls) or (.xlsx)');", true); extFlag = false; } string fileLocation = Server.MapPath("../ExcelReport/" + fileName); file_Upload_DataFile.SaveAs(fileLocation); if (fileExtension == ".xls") { connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; extFlag = true; } else if (fileExtension == ".xlsx") { connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; extFlag = true; } } if (extFlag != false) { OleDbConnection con = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = con; OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd); //DataSet ds = new DataSet(); DataTable dtExcelRecords = new DataTable(); con.Open(); DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString(); cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]"; dAdapter.SelectCommand = cmd; dAdapter.Fill(dtExcelRecords); con.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)