Is it possible to read from a url into a System.IO.Stream object?

swolff1978 picture swolff1978 · Aug 3, 2009 · Viewed 36k times · Source

I am attempting to read from a url into a System.IO.Stream object. I tried to use

Dim stream as Stream = New FileStream(msgURL, FileMode.Open)

but I get an error that URI formats are not supported with FileStream objects. Is there some method I can use that inherits from System.IO.Stream that is able to read from a URL?

Answer

Thomas Levesque picture Thomas Levesque · Aug 3, 2009

Use WebClient.OpenRead :

Using wc As New WebClient()
    Using stream As Stream = wc.OpenRead(msgURL)
        ...
    End Using
End Using