tags:

views:

31

answers:

2

imagesHello -

I want to display a picture from a local folder in a picturebox, however if that picture fails to load, I woud like to download the image from a website and display it. I have no idea how to do this, but what I have is this:

try
                {
                    pictureBox1.Image = System.Drawing.Image.FromFile("images\\" + filename + "_0001.gif");
                    XmlIn1.Close();
                }

                catch
                {
                    string downloadPath = "http://www.website.com/images/" + filename + "_0001.gif";

                    pictureBox1.Image = System.Drawing.Image.FromFile(downloadPath);

                    XmlIn1.Close();

                }
+2  A: 

Why not use the ImageLocation property?

pictureBox1.ImageLocation = "http://skins.gmodules.com/ig/images/logos/approved/beveled_white.png";

Above code will display Google Logo from Web.

Shoban
A: 

try something like

WebClient wc = new WebClient();
MemoryStream ms = new MemoryStream(wc.DownloadData(<imgURL>));
pictureBox1.Image = Image.FromStream(ms);
GxG