I am trying to open a file and read the data contained in it, it is a txt file, below is the code I am attempting to use
I get an error saying
"value of type "Stream" Cannot be converted to "String""
I don't know how to correct this and what I am doing wrong. Ultimately I want to have the data go to TextBox1 .
Thanks in Advance
Dave
Code:
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim strm As System.IO.Stream
strm = OpenFileDialog1.OpenFile()
'Dim strm As System.IO.Stream
'strm = OpenFileDialog1.OpenFile()
TextBox1.Text = OpenFileDialog1.FileName.ToString()
If Not (strm Is Nothing) Then
'insert code to read the file data
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(strm)
MsgBox(fileReader)
strm.Close()
MessageBox.Show("file closed")
End If
End Sub
"value of type "Stream" Cannot be converted to "String""
I don't know how to correct this and what I am doing wrong. Ultimately I want to have the data go to TextBox1 .
Thanks in Advance
Dave