Writing to textbox from a file

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
 
M

Mythran

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
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top