Writing to textbox from a file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a text file with some text in.
I have a textbox called textbox1 for example.
what do I do so when I click on a button (button1) it opens the text file in
the textbox so I can edit it.
also how do I save it

I am newbie as you can tell. I have tried and looked on the msdn but I am
stuggling.

Cheers Russ
 
Russell said:
Hi,
I have a text file with some text in.
I have a textbox called textbox1 for example.
what do I do so when I click on a button (button1) it opens the text file
in
the textbox so I can edit it.
also how do I save it

I am newbie as you can tell. I have tried and looked on the msdn but I am
stuggling.

Cheers Russ

Dim stream As IO.StreamWriter = New IO.StreamWriter(pathtotextfile)
stream.Write(txtTextBox1.Text)
stream.Close()


Hope this helps ;)

Mythran
 
Russel,

Have a look at these pages where are links inside. There are samples and one
of those will probably include your question or almost your question.

What you have to do is
Create a windowsform project
Drag from your toolbox on the left a textbox to the form
Drag a button on your form
Click on that button
Insert this code inside the sub you see.

\\\\
Try
Dim sr As New StreamReader("Your Path of the file")
textBox1. = sr.ReadToEnd()
sr.Close()
Catch Ex As Exception
' Let the user know what went wrong.
MessageBox.Show("The file could not be read:" & Ex.Message)
End Try
////

Do debug start

A link
http://msdn.microsoft.com/library/d.../html/frlrfsystemiostreamreaderclasstopic.asp

I hope this helps,

Cor
 
Back
Top