private void btn_Browse_Click_1(object sender, EventArgs e) { try { lblMessage.Text = ""; btn_Browse.Enabled = false; btnUploadFile.Enabled = false; openFile.DefaultExt = ".xlsx"; openFile.Filter = "(.xlsx)|*.xlsx"; if (openFile.ShowDialog() == DialogResult.OK) { //progressBar.Visible = true; //progressBar.Style = ProgressBarStyle.Marquee; //System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(LoadData(excelSheet))); //thread.Start(); this.progressIndicatorBrowse.Image = Properties.Resources.ProgressBrowse; txtFilePath.Text = openFile.FileName; Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook excelBook = excelApp.Workbooks.Open(txtFilePath.Text.ToString(), 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); //Microsoft.Office.Interop.Excel.Worksheet excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelBook.Worksheets.get_Item(Convert.ToInt32(ConfigurationManager.AppSettings["SpreadSheetIndex"])); ; //LoadData(excelSheet); List <Name> namedRanges = excelBook.GetNamedRanges(); LoadData(namedRanges); //Dispose Excel Objects excelBook.Close(0); excelApp.Quit(); btn_Browse.Enabled = true; btnUploadFile.Enabled = true; this.progressIndicatorBrowse.Image = null; } } catch (Exception ex) { this.progressIndicatorBrowse.Image = null; lblMessage.Text = "The File you are trying to upload is not an Excel File, please try again." + System.Environment.NewLine + "Exception Details: " + System.Environment.NewLine + ex.Message; lblMessage.ForeColor = System.Drawing.Color.Red; lblMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 10); btn_Browse.Enabled = true; btnUploadFile.Enabled = true; } }