if (FileUpload1.HasFile) { ddlParty.Enabled = true; } String strConnection = "ConnectionString"; string connectionString = ""; if (FileUpload1.HasFile) { string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName); string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName); string fileLocation = Server.MapPath("~/App_Data/" + fileName); FileUpload1.SaveAs(fileLocation); if (fileExtension == ".xls") { connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; } else if (fileExtension == ".xlsx") { connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; } OleDbConnection con = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = con; OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd); 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); gvExcelFile.DataSource = dtExcelRecords; gvExcelFile.DataBind(); }
"18/08/2016"
"IMEX=1"
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)