private void button3_Click(object sender, EventArgs e) { using (var selectFileDialog = new OpenFileDialog()) { if (selectFileDialog.ShowDialog() == DialogResult.OK) { var tbl = _variableService.Compare(comboBox1.Text, selectFileDialog.FileName); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Excel|*.xlsx"; saveFileDialog1.Title = "Save file"; saveFileDialog1.ShowDialog(); // If the file name is not an empty string open it for saving. if (saveFileDialog1.FileName != "" && Path.GetExtension(saveFileDialog1.FileName) == ".xlsx") { _variableService.ExportCompare(saveFileDialog1.FileName, comboBox1.Text, tbl); } } } }