private void TryToSaveSpreadsheet(SqlRunParameters srp) { string fileName = ""; try { fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "TSqlFlex" + DateTime.Now.ToString("_yyyyMMddTHHmmss") + ".xml"); } catch (Exception ex) { string error = "Exception when attempting to find personal documents folder for current user. Will not save file."; logger.Log(error + " " + ex.Message); logger.Log(ex.StackTrace); MessageBox.Show(error + " " + ex.Message); fileName = ""; } if (fileName != "") { srp.saveOutputStreamTo(srp.outputFiles[0], fileName); this.lastExportedFilePath = fileName; InvokeFireAndForgetOnFormThread(() => { txtOutput.Text = "--Results written to \"" + fileName + "\".\r\n--You can open this file in Excel.\r\n\r\n"; }); } }
private void TryToSaveCSVs(SqlRunParameters srp) { txtOutput.Text = ""; string personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string timestamp = DateTime.Now.ToString("_yyyyMMddTHHmmss"); for (int csvIndex = 0; csvIndex < srp.outputFiles.Count; csvIndex += 1) { string fileName = ""; try { fileName = Path.Combine(personalFolder, "TSqlFlex" + timestamp + (srp.outputFiles.Count > 1 ? "_" + (csvIndex + 1).ToString() : "") + ".csv"); } catch (Exception ex) { string error = "Exception when attempting to find personal documents folder for current user. Will not save file."; logger.Log(error + " " + ex.Message); logger.Log(ex.StackTrace); MessageBox.Show(error + " " + ex.Message); fileName = ""; break; } if (fileName != "") { srp.saveOutputStreamTo(srp.outputFiles[csvIndex], fileName); this.lastExportedFilePath = fileName; InvokeFireAndForgetOnFormThread(() => { txtOutput.Text += "--Results written to \"" + fileName + "\".\r\n--You can open this file in your text editor.\r\n\r\n"; }); } } }