Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 581313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:33:55+00:00 2026-05-13T14:33:55+00:00

Okay so here is a random error. I’m dynamically adding images to an html

  • 0

Okay so here is a random error. I’m dynamically adding images to an html page. The images are on another server that I do not have control of. The images are named something like this:
imageName10.jpg
imageName11.jpg
imageName13.jpg
imageName14.jpg
imageName16.jpg
imageName17.jpg
imageName19.jpg

Lets take the list of images above. I want to get all the images available, but I do not know how many there are. I do know that it starts with the string “imageName”, has a number between 10 and 20 and then ends with the string “.jpg”. I decided to create a loop from 10 to 20 creating the image name and adding the image tags to my html. This works, however I do not want to add broken links so I want to first check if the image exists. To do this I used a WebRequest to get the image url with a timeout of 5 seconds. If it times out it basically skips over the link and continues the loop.

        String dynamicHtmlStr = String.Empty;
        dynamicHtmlStr += "<TABLE>";
        WebRequest webReq = null;
        WebResponse webResp = null;
        for (int i = 10; i < 20; i++)
        {
            try
            {
                webReq = WebRequest.Create("http://www.someurl.com/image/imageName" + i + ".jpg");
                webReq.Timeout = 5000;
                webResp = webReq.GetResponse();

                dynamicHtmlStr += "<TR>";
                dynamicHtmlStr += "<TD>";
                dynamicHtmlStr += "<IMG http://www.someurl.com/image/imageName" + i + ".jpg"\">";
                dynamicHtmlStr += "</TD>";
                dynamicHtmlStr += "</TR>";
            }
            catch (Exception)
            {
            }
        }
        dynamicHtmlStr += "</TABLE>";
        return dynamicHtmlStr;

My issue is this:
After the webrequest fails the first time. all other web requests after that seem to fails too. For instance, take the image list above. The loop starts at 10. it does a web request to see if “imageName10.jpg” exists, gets a good response, I add the html string to the dynamicHtmlStr variable. It loops again, this time on 11 and eveything is still fine. Then we move on to 12. 12 is false and does not add to the dynamicHtmlStr because it does not exists, which is correct. We move onto 13 which does exist, but this too fails and every other web request after that, regardless of if it exists or not.

This makes no sense to me. Am I doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:33:56+00:00Added an answer on May 13, 2026 at 2:33 pm

    The situation is a bit odd, I must say.

    I tend to use the HttpWebRequest / HttpWebResponse classes with great success directly with the streams.

    The request is quite straightforward, have a look here and here.

    Once you have created your request, you can look at the response here:

    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        using (Stream responseStream = response.GetResponseStream())
        {
            using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
            {
               // Put in code to check response status. You'll probably get a 404 when not found.
            }
        }
    }
    

    Another note: I know that the loop size is minute, but you should always try to use a StringBuilder for iterative string concatenation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

Okay, I have been messing around with different sorting algorithms in Ruby; mainly variations
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
I found some source code in this thread posted by Rex Logan here on
I have this extremely simple splash page here: http://iph0wnz.com It has the main graphic
okay, so i have a text file with example content below line1with some random

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.