Jump to content
  • Advertisement
Sign in to follow this  

VB.NET casting to System.IO.StreamReader

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an open file Dialog box and I am trying to get the stream from that dialog box, but I need to cast from a Stream to a StreamReader, but when I do I am getting this error: "error BC30311: Value of type 'System.IO.Stream' cannot be converted to 'System.IO.StreamReader'" here's my code snippet:
            Dim FileDiag As New OpenFileDialog
            FileDiag.InitialDirectory = "C:\"
            FileDiag.Filter = "Text files (*.txt)|*.txt"
            FileDiag.FilterIndex = 1
            FileDiag.RestoreDirectory = True

            If FileDiag.ShowDialog() = DialogResult.OK Then
                'The error is on the line below
                m_InputStream = CType(FileDiag.OpenFile(), System.IO.StreamReader)
                If Me.m_InputStream Is Nothing Then
                    Throw New Exception("Error opening the file")
                End If

                Me.m_InputFilename.Text = FileDiag.FileName

            End If

what am I doing wrong? ~guyaton

Share this post

Link to post
Share on other sites
OpenFile returns a Stream, pass this to the StreamReader constructor to read from it, something like this:

m_InputStream = new System.IO.StreamReader(FileDiag.OpenFile())

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!