private void btn_exportExcel_Click(object sender, EventArgs e) { if (txt_packingNo.Text.Trim() == "") { MessageBox.Show("please type slip code !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); txt_packingNo.Focus(); return; } if (dtgv_deliveryInfo.Rows.Count == 0) { MessageBox.Show("Delivery data is empty, please check picking slip code !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string pathsave = ""; System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Browse Excel Files"; saveFileDialog.DefaultExt = "Excel"; saveFileDialog.Filter = "Excel files (*.xls)|*.xls"; saveFileDialog.CheckPathExists = true; if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { pathsave = saveFileDialog.FileName; saveFileDialog.RestoreDirectory = true; if (dtExport.Rows.Count > 0) { Controller.ExportCustomsDeclaration customsDeclaration = new Controller.ExportCustomsDeclaration(); var exportResult = customsDeclaration.ExportCustomsDecalarationsGroupByProduct(pathsave, dtExport, listSummary, txt_buyerSelect.Text.Trim(), txt_ShipmentType.Text.Trim()); if (exportResult) { var resultMessage = MessageBox.Show("Customs Declaration exported to excel sucessful ! \n\r Do you want to open this file ?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (resultMessage == DialogResult.Yes) { FileInfo fi = new FileInfo(pathsave); if (fi.Exists) { System.Diagnostics.Process.Start(pathsave); } else { MessageBox.Show("File doestn't exist !", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } } }