Quantcast
Viewing all articles
Browse latest Browse all 15648

Need help reading from a file

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

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

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

Viewing all articles
Browse latest Browse all 15648

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>