private void LoadSheetNames() { try { if (SourceType == SourceType.Excel && File.Exists(txtFilePath.Text) && !_isLoading) { var sheetNames = ExcelParser.GetSheetNames(txtFilePath.Text); cboSheetName.DataSource = sheetNames; cboSheetName.SelectedIndex = sheetNames.Count > 0 ? 0 : -1; } else { cboSheetName.DataSource = null; cboSheetName.SelectedIndex = -1; } } catch (IOException ex) { if (ex.Message.Contains("The process cannot access the file")) { if ( MessageBox.Show("The specified Excel file is open.\r\nPlease close the file before you retry parsing sheet names!\r\n(Cancel will close the application)", "Sheet names can not be parsed", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation) == DialogResult.Retry) { LoadSheetNames(); } else { Application.Exit(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Generate", MessageBoxButtons.OK, MessageBoxIcon.Error); } }