protected void btnUpload_Click(object sender, EventArgs e) { if (ddlSPList.SelectedValue != "0") { spListGuid = ddlSPList.SelectedValue.Trim().ToString(); SPSecurity.RunWithElevatedPrivileges(delegate() { try { CreateDirectory(); excelPath = HttpContext.Current.Server.MapPath("/_layouts/Temp/" + fuExcelSheet.FileName); if (fuExcelSheet.FileName != string.Empty) { if (excelPath.EndsWith("xls", StringComparison.InvariantCultureIgnoreCase)) { excelExten = "xls"; xlConn = new global::System.Data.OleDb.OleDbConnection(Providers.Utilities.ConnUtilities.CreateXlConnectionString(excelPath, excelExten)); ddlSheetName.DataSource = DataAccessProvider.GetExcelSheetNames(xlConn); ddlSheetName.DataBind(); btnShowData.Visible = true; ddlSheetName.Visible = true; this.Page.ClientScript.RegisterStartupScript(GetType(), "key", "document.getElementById('light').style.display='block';", true); } else if (excelPath.EndsWith("xlsx", StringComparison.InvariantCultureIgnoreCase)) { excelExten = "xlsx"; xlConn = new global::System.Data.OleDb.OleDbConnection(Providers.Utilities.ConnUtilities.CreateXlConnectionString(excelPath, excelExten)); ddlSheetName.DataSource = DataAccessProvider.GetExcelSheetNames(xlConn); ddlSheetName.DataBind(); this.Page.ClientScript.RegisterStartupScript(GetType(), "key", "document.getElementById('light').style.display='block';", true); litMessage.Text = string.Empty; btnShowData.Visible = true; ddlSheetName.Visible = true; } else { litMessage.Text = "Please Upload .xls or .xlsx file"; } } else { litMessage.Text = "Please provide a valid file path"; } } catch (Exception ex) { litMessage.Text = "Incorrect Format"; rptBindColumns.Visible = false; SPErrorLogs.LogExceptionToSPLog(oWebpartName, "btnUpload_Click", ex); } }); } }