# Read a text file

**URL:** <https://forums.thehomestack.io/t/read-a-text-file/62>\
**Category:** vb.Net\
**Created:** [October 15, 2003, 3:51am UTC](https://forums.thehomestack.io/t/read-a-text-file/62 "2003-10-15T03:51:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![robinhood1995](https://forums.thehomestack.io/letter_avatar_proxy/v4/letter/r/48db29/32.png) [@robinhood1995](https://forums.thehomestack.io/u/robinhood1995)\
**Post date:** [October 15, 2003, 3:51am UTC](https://forums.thehomestack.io/t/read-a-text-file/62/1 "2003-10-15T03:51:45Z")

</div>

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
