views:

117

answers:

1

As part of my current project I am required to download images from a related website, given the URL of the image. (No ethics dilemas please people, already checked the legal status and it's fine)

What is the most effective way to do this in C#? I would prefer if the method was synchronous, as asynchronous methods tend to be a little complex when integrated into a web-page and there is no need for such complexity as it is not a front-end user function.

Cheers, Ed

+4  A: 

Use the DownloadData method in the WebClient class:

byte[] imageData;
using (WebClient client = new WebClient()) {
   imageData = client.DownloadData(url);
}
Guffa