11.4. Download a File and Process It Using a Stream

Problem

You need to retrieve a file from a web site, but you do not want to save it directly to the hard drive, or you do not have permission to do so. Instead, you need to process the data in your application directly in memory.

Solution

Use the System.Net.WebRequest class to create your request, the System.Net.WebResponse class to retrieve the response from the web server, and some form of reader (typically a System.IO.StreamReader for HTML or text data, or a System.IO.BinaryReader for a binary file) to parse the response data.

NOTE

You could also use the OpenRead method of the System.Net.WebClient class to open a stream. However, the additional capabilities of the WebRequest and WebResponse ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.