Downloading an image from web
-
Hi, Can you kindly shed some light on what's wrong with the below code? Many thanks,
private Image DownloadImage(string \_URL) { try { WebClient client = new WebClient(); Stream stream = client.OpenRead(\_URL); //The problem seems to be here Image img = Image.FromStream(stream); stream.Flush(); stream.Close(); return img; } catch (Exception e) { MessageBox.Show(e.Message); return null; } }
-
Hi, Can you kindly shed some light on what's wrong with the below code? Many thanks,
private Image DownloadImage(string \_URL) { try { WebClient client = new WebClient(); Stream stream = client.OpenRead(\_URL); //The problem seems to be here Image img = Image.FromStream(stream); stream.Flush(); stream.Close(); return img; } catch (Exception e) { MessageBox.Show(e.Message); return null; } }
Muammar© wrote:
The problem seems to be here
what problem?
Muammar© wrote:
The problem seems to be here
looking at the full exception, not just its messge, would tell you exactly where it happens :(
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Hi, Can you kindly shed some light on what's wrong with the below code? Many thanks,
private Image DownloadImage(string \_URL) { try { WebClient client = new WebClient(); Stream stream = client.OpenRead(\_URL); //The problem seems to be here Image img = Image.FromStream(stream); stream.Flush(); stream.Close(); return img; } catch (Exception e) { MessageBox.Show(e.Message); return null; } }
-
Too little information - however, if you are getting a
WebException
, either your URL is not valid or there is some error while downloading data. Check that the URL you are passing is correct. -
Hi, Can you kindly shed some light on what's wrong with the below code? Many thanks,
private Image DownloadImage(string \_URL) { try { WebClient client = new WebClient(); Stream stream = client.OpenRead(\_URL); //The problem seems to be here Image img = Image.FromStream(stream); stream.Flush(); stream.Close(); return img; } catch (Exception e) { MessageBox.Show(e.Message); return null; } }
private void button1_Click(object sender, EventArgs e) { WebClient wc = new WebClient(); wc.DownloadFileAsync(new Uri("http://www.xxxx.com/xx.gif"), "D:\\xx.gif"); wc.DownloadFileCompleted+=new AsyncCompletedEventHandler(wc_DownloadFileCompleted); } private void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { MessageBox.Show("完成!"); }
-
Hi, Can you kindly shed some light on what's wrong with the below code? Many thanks,
private Image DownloadImage(string \_URL) { try { WebClient client = new WebClient(); Stream stream = client.OpenRead(\_URL); //The problem seems to be here Image img = Image.FromStream(stream); stream.Flush(); stream.Close(); return img; } catch (Exception e) { MessageBox.Show(e.Message); return null; } }
-
private void button1_Click(object sender, EventArgs e) { WebClient wc = new WebClient(); wc.DownloadFileAsync(new Uri("http://www.xxxx.com/xx.gif"), "D:\\xx.gif"); wc.DownloadFileCompleted+=new AsyncCompletedEventHandler(wc_DownloadFileCompleted); } private void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { MessageBox.Show("完成!"); }
-
private void button1_Click(object sender, EventArgs e) { WebClient wc = new WebClient(); wc.DownloadFileAsync(new Uri("http://www.xxxx.com/xx.gif"), "D:\\xx.gif"); wc.DownloadFileCompleted+=new AsyncCompletedEventHandler(wc_DownloadFileCompleted); } private void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { MessageBox.Show("完成!"); }
Ahem. You forgot to reallocate the reference to your event handler.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility