Saturday, August 2, 2014

C# Snippet - Saving TextBox Text to File

This snippet will show you how to save text from a TextBox to a text file document (plaintext file).



  • try
  • {
  • StreamWriter sw = new StreamWriter(txtFilename.Text);
  • sw.Write(txtContent.Text);
  • sw.Close();
  • }
  • catch (IOException iex)
  • {
  • MessageBox.Show(iex.Message, this.Text);
  • }
  • catch (Exception ex)
  • {
  • MessageBox.Show(ex.Message, this.Text);
  • No comments: