Friday 20 July 2012

StreamReader in vb.net

In this tutorial, you learn how to read the text from a text file using the StreamReader. using StreamReader  you can read file and write file append the text to file .

copy and paste below 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

No comments:

Post a Comment