C# - Download Image from an URL

By [)ia6l0 iii

Use the following code snippet to download an image from an URL.

Image _downloadedImage = null;
System.Net.WebResponse _downloadImageResponse = null;

try
{
        System.Net.HttpWebRequest _downloadHWRequest = stem.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL);.
        _downloadHWRequest.AllowWriteStreamBuffering = true;.
        _downloadHWRequest.Timeout = 30000;.
_downloadHWRequest.GetResponse();.
        System.IO.Stream _WebStream = _downloadImageResponse .GetResponseStream();.
       _downloadedImage = Image.FromStream(_WebStream);.
    }
catch
(
//Your exceptions
)
finally
{
       _downloadImageResponse.close();
}

Related FAQs

Use the WebClient class from System.Net namespace to download and save a file.
C# - Download Image from an URL  (3894 Views)