How can I easily download a file from internet in C#?
Thank you very much.
How can I easily download a file from internet in C#?
Thank you very much.
Have a look at the BCL class System.Net.WebRequest
. Here's a brief example:
using System.Net;
...
var request = WebRequest.Create(new Uri("http://..."));
var response = request.GetResponse();
var responseStream = response.GetResponseStream();
// ^^^^^^^^^^^^^^
// read web resource content through this stream object!
...
Take note:
Some of these objects are IDisposable
, so in real code you might want to wrap them in using
blocks.
The above code example does not do any error checking. You might want to add appropriate code for this, also.