Click here to Skip to main content
15,312,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
     StreamReader stream = new StreamReader(bulkfile);
     foreach (string line in System.IO.File.ReadLines(bulkfile))
     {
        var webRequest = HttpWebRequest.Create(line);
         webRequest.Method = "HEAD";
         try
          {
           HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(line);
           using (HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse())
        {
       if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
          {
       using (var webResponse = webRequest.GetResponse())
          { 
     var fileSize = webResponse.Headers.Get("Content-Length");
     var fileSizeInMegaByte = Math.Round(Convert.ToDouble(fileSize)/1024.0/ 1024.0, 2);
              richTextBox1.Text = "<" + myHttpWebResponse.StatusCode + ">"+"<" + fileSizeInMegaByte + " MB" + ">" + "<" + line + ">";

                            }
                        }
                    }
                }
                catch
                {
                    richTextBox1.Text = "End of File.";
                }

            }

        }

    }
}


What I have tried:

This code reads URL's from a text file and then gets the response and displays it according to this below but for each URL it displays it and then disappears and displays the next one. I want it to show for all the lines and stay on the screen in my textbox.

richTextBox1.Text = "<" + myHttpWebResponse.StatusCode + ">"+"<" + fileSizeInMegaByte + " MB" + ">" + "<" + line + ">";
Posted
Updated 25-Oct-21 10:58am
v7
Comments
Richard Deeming 25-Oct-21 6:36am
   
Removing the content of your question after it has been answered is extremely rude.

I have rolled back your destructive edit.
Richard Deeming 26-Oct-21 4:19am
   
Once again, you have removed the content of your question after it has been answered. You are clearly a troll who doesn't want our help.

1 solution

Look at your code, you set the textbox to the HTTPResponse for a URL. But then next time round the loop you do the same. So after processing all URLs the only data you show is from the last one processed. You need to append the response to the textbox each time. Use the TextBoxBase.AppendText(String) Method (System.Windows.Forms) | Microsoft Docs[^] to add each block of text.
   
Comments
[no name] 24-Oct-21 7:25am
   
@Richard It worked for me thank you but I seem to be stuck again since I tried to return it to my main form but it only sends me back one line, I've updated the question with my altered code, could you take a look at it please?
Richard MacCutchan 24-Oct-21 7:37am
   
You are doing the same as before. You set the variable s to the current text each time round the loop. So at the end of the loop s will only contain the last text read. Instead of using a String variable use a StringBuilder Class (System.Text) | Microsoft Docs[^], and append each line as you process it.
[no name] 24-Oct-21 13:39pm
   
got it. Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900