Export from textbox to external file
-
I am fairly new to C# and am trying to export the text from a multi-line textbox to an external file. I am familiar with SaveFileDialog when exporting the contents of a DataGrid, but am unsure as to how I would assign the textbox data. Here is what I would have done if I were exporting the data from a C1TrueDBGrid. I am sure that I am just missing something simple :) ------------------------------------------------------- protected virtual void Export() { System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog() ; saveFileDialog.Filter = "Excel |*.csv|Text|*.txt" ; saveFileDialog.InitialDirectory = @"C:\" ; saveFileDialog.OverwritePrompt = true ; saveFileDialog.FileName = "dbview_" + this.tableName.Replace(" ", ""); saveFileDialog.Title = "Database View for " + this.tableName.TrimEnd() ; saveFileDialog.ShowDialog() ; try { if (System.IO.File.Exists(saveFileDialog.FileName)) { System.IO.File.Delete(saveFileDialog.FileName) ; } this.c1TrueDBGrid1.ExportToDelimitedFile(saveFileDialog.FileName, C1.Win.C1TrueDBGrid.RowSelectorEnum.AllRows, ",", "", "", true, "ASCII") ; System.Diagnostics.Process.Start(saveFileDialog.FileName) ; } catch {} }
-
I am fairly new to C# and am trying to export the text from a multi-line textbox to an external file. I am familiar with SaveFileDialog when exporting the contents of a DataGrid, but am unsure as to how I would assign the textbox data. Here is what I would have done if I were exporting the data from a C1TrueDBGrid. I am sure that I am just missing something simple :) ------------------------------------------------------- protected virtual void Export() { System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog() ; saveFileDialog.Filter = "Excel |*.csv|Text|*.txt" ; saveFileDialog.InitialDirectory = @"C:\" ; saveFileDialog.OverwritePrompt = true ; saveFileDialog.FileName = "dbview_" + this.tableName.Replace(" ", ""); saveFileDialog.Title = "Database View for " + this.tableName.TrimEnd() ; saveFileDialog.ShowDialog() ; try { if (System.IO.File.Exists(saveFileDialog.FileName)) { System.IO.File.Delete(saveFileDialog.FileName) ; } this.c1TrueDBGrid1.ExportToDelimitedFile(saveFileDialog.FileName, C1.Win.C1TrueDBGrid.RowSelectorEnum.AllRows, ",", "", "", true, "ASCII") ; System.Diagnostics.Process.Start(saveFileDialog.FileName) ; } catch {} }
Here is part of an example from MSDN that shows how to write text to a file:
StreamWriter sr = File.CreateText(FILE_NAME); sr.WriteLine ("This is my file."); sr.WriteLine ("I can write ints {0} or floats {1}, and so on.", 1, 4.2); sr.Close();
--- b { font-weight: normal; } -
Here is part of an example from MSDN that shows how to write text to a file:
StreamWriter sr = File.CreateText(FILE_NAME); sr.WriteLine ("This is my file."); sr.WriteLine ("I can write ints {0} or floats {1}, and so on.", 1, 4.2); sr.Close();
--- b { font-weight: normal; }