4

Hi i'm newbie in C# developer. I would like to save a text-file to database. I watched some videos on Youtube. They use Memorystream to save image:

MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

Now i try to save a text from a textbox? Can i have similar way to do it? Thank you

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
Cao Linh Truong
  • 253
  • 8
  • 20
  • Saving a string to a memory stream? See [SO question][1] [1]: http://stackoverflow.com/questions/8047064/convert-string-to-system-io-stream – Josh Aug 07 '12 at 20:32

2 Answers2

4

Try this:

MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(myTextBox.Text))
Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
0

Yes, you can.

Try something like this.

MemoryStream ms = new MemoryStream();
ms.Write(System.Text.Encoding.UTF8.GetBytes(textBox1.Text), 0, textBox1.Length);
Steve Danner
  • 21,818
  • 7
  • 41
  • 51