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?
Stream: System. IO. Stream is an abstract class that provides standard methods to transfer bytes (read, write, etc.) to the source. It is like a wrapper class to transfer bytes. Classes that need to read/write bytes from a particular source must implement the Stream class.
The stream is basically the sequence of bytes passing through the communication path. There are two main streams: the input stream and the output stream. The input stream is used for reading data from file (read operation) and the output stream is used for writing into the file (write operation).
A character file is a hardware file that reads/writes data in character by character in a file. These files provide a serial stream of input or output and provide direct access to hardware devices.
Use WebClient.OpenRead
:
Using wc As New WebClient()
Using stream As Stream = wc.OpenRead(msgURL)
...
End Using
End Using
VB.Net:
Dim req As WebRequest = HttpWebRequest.Create("url here")
Using stream As Stream = req.GetResponse().GetResponseStream()
End Using
C#:
var req = System.Net.WebRequest.Create("url here");
using (Stream stream = req.GetResponse().GetResponseStream())
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With