Loading WebImages onto the Windows Application


Here is the solution for loading webimages onto the windows application.
1) The first thing that we need is to create a HttpWebRequest object from the Image URL.
2) GetResponse will get the resulting response from the request we have made.
3) From GetResponseStream method of HttpWebResponse we can get the Stream of the URL.
4) After getting the Stream objtect, create an Image object from it.
        private Image GetImageFromWeb(string strURL)
            Stream streamImage = null;
                //Create a web request to the url containing the image
                HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(strURL);
                //gets the response from the web request
                HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();
                //return the image stream from the URL specified earlier
                streamImage = wRes.GetResponseStream();
            catch (Exception Ex)
            if (streamImage != null)
                return Image.FromStream(streamImage);
                return null;

Now you got the image, you can give it to the picturebox and that will display the image.
Lets say, we have pbxImage(PictureBox) is there on the form.
then just the write the below line in your code, that will load the image from the web.
                  string strURL = “”;

                 pbxImage .Image = GetImageFromWeb(strURL);

Hope this helps

Happy Coding

One thought on “Loading WebImages onto the Windows Application

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s