42. Reading Text Files
In this tutorial, we learn how to read the text from a text file using the StreamReader.
Code
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If System.IO.File.Exists(TextBox1.Text) = True Then
Dim objreader As New System.IO.StreamReader(TextBox1.Text)
TextBox2.Text = objreader.ReadToEnd
objreader.Close()
Else
MessageBox.Show("That file does not exist!")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox2.Clear()
End Sub
End Class
