Read a text file

This code will read the win.ini file and separate it with char(10) and char(13) which is a <cr> <lf> and place it’s values in a text box.

Private Sub btnReadTextFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadTextFile.Click
Dim winPath As String
Dim s As String
Dim fname As String
Dim sr As StreamReader
Dim ex As Exception
’ get the windows folder name
winPath = System.Environment. _
GetEnvironmentVariable(“SystemRoot”)
If winPath = “” Then
MessageBox.Show("Unable to retrieve the " & _
“Windows path.”, “Error Reading Windows Path”, _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
fname = winPath & “\win.ini”
If File.Exists(fname) Then
Try
sr = File.OpenText(fname)
s = sr.ReadToEnd
sr.Close()
textbox1.text = s
Catch ex
MessageBox.Show(ex.message)
return
End Try
Else
MessageBox.Show(“The file " & fname & _
" does not exist.”)
Return
End If
End Sub