Can't download image from web RRS feed

  • Question

  • hello,

    please help me.

    i'm tryin gto download an image from a website. I tried a lot of methods and always I can download the image ti my computer, but when I try to open the image i get the folllowing error: "Can't open this icture because the file appears to damaged, corrupted or is too large"

    I used a code that I used other times and allways worked fine, I don't know what happens.

    this is the link to the image:                    2080/is_not_main:1/imageno:2


     using (System.Net.WebClient client = new System.Net.WebClient())

                            client.DownloadFile(new Uri(""), @"c:\temp\image251.jpg");



    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("                    2080/is_not_main:1/imageno:2");
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if ((response.StatusCode == HttpStatusCode.OK ||
                    response.StatusCode == HttpStatusCode.Moved ||
                    response.StatusCode == HttpStatusCode.Redirect)) 
                    using (Stream inputStream = response.GetResponseStream())
                    using (Stream outputStream = File.OpenWrite(@"c:\temp\image15.png"))
                        byte[] buffer = new byte[4096];
                        int bytesRead;
                            bytesRead = inputStream.Read(buffer, 0, buffer.Length);
                            outputStream.Write(buffer, 0, bytesRead);
                        } while (bytesRead != 0);

    • Edited by Mie Mie Thursday, October 26, 2017 3:06 AM
    Thursday, October 26, 2017 3:01 AM

All replies

    • Proposed as answer by Ashidacchi Thursday, October 26, 2017 6:13 AM
    Thursday, October 26, 2017 5:59 AM
  • So thanks , Castorix31

    I try with this link,

    But the same error.
    Why?, I don't know.

    Thursday, October 26, 2017 8:00 AM
  • Now, your image doesn't exist anymore...
    Thursday, October 26, 2017 8:20 AM
  • Hi Mie Mie,

    Thank you for posting here.

    For your question, I tried many ways to download the image.

    I use the following code to get the image url from img src of the website.

                var document = new HtmlWeb().Load("");
                var urls = document.DocumentNode.Descendants("img")
                                                .Select(e => e.GetAttributeValue("src", null))
                                                .Where(s => !String.IsNullOrEmpty(s));
                List<string> list = urls.ToList();

    But when I try to download the image, I get the same error as yours. We could not open the image. I check the herder of the image, the data is not compressed.

      using (WebClient client = new WebClient())
                    client.DownloadFile(list[2], "image35.jpg");

    After that, I try to check the url which get from the <img src="" >. I find that if we open the url in the same browser which link open the website below, we could open the image in the website. I check the data it received from cache.

    This is one of the url get from <img src="">.

    This is the link which open the website.

    But when we open the image via url in different browser without open the link, we could not get the image.

    The website will show that a restriction is made by referring directly to an image from an external site.

    Our goal is to provide a comfortable and useful service for everyone on this website.
    Therefore, a restriction is made by referring directly to an image from an external site.
    In addition, depending on your environment and software,
    Images may not be displayed.

    Hence, we could not download the image.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, October 27, 2017 9:36 AM