Wednesday, May 29, 2013

Read txt File in RichtextBox

 Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
        'Specify file
        Dim myfile As String = "C:\test.txt"
        'Check if file exists
        If System.IO.File.Exists(myfile) = True  Then
            'Read the file
            Dim objReader As New System.IO.StreamReader(myfile)
            'Save file contents to textbox
            RichTextBox1.Text = objReader.ReadToEnd
            objReader.Close()
        Else
            MsgBox("File not found!")
        End If
    End Sub