private void Menu_File_SaveAs__Click(object sender, EventArgs e) { if (pathCurrent == null) { pathCurrent = ""; } if (data != null) { using (SaveFileDialog SaveDlg = new SaveFileDialog()) { SaveDlg.Filter = "PMD Placement Data|*.plb"; SaveDlg.FileName = Path.GetFileName(pathCurrent); if (SaveDlg.ShowDialog() == DialogResult.OK) { Stream file = null; try { MessagePrinter.ClearMsg(); pathCurrent = SaveDlg.FileName; //store file path file = new FileStream(pathCurrent, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); data.Build(new PLBWriter(file)); fileCurrent = Path.GetFileName(pathCurrent); SetDirty(false); MessagePrinter.ShowMsg("There were some issues while saving:", "Warning!"); } catch (Exception ex) { MessageBox.Show( //show error message "An error occured while saving:\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { file?.Close(); } } } } }