Read txt from a file.

stefonalfaro

Member
Joined
Dec 3, 2007
Messages
16
Programming Experience
Beginner
When I click on button1 I want it to opena file that I choose and display the text in textbox1. If this is even possible I would like an answer
 
Dim Fs As FileStream = New FileStream("c:\textfile.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim sr As New StreamReader(Fs)
Dim str As String
str = sr.ReadToEnd()

'I used a rich text box to display the file in
rtbData.Text = str
 
dont forget:
sr.close


VB.NET:
Dim Fs As FileStream = New FileStream("c:\textfile.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim sr As New StreamReader(Fs)
Dim str As String
str = sr.ReadToEnd()
sr.Close()

'I used a rich text box to display the file in
rtbData.Text = str
 
Back
Top