0

I am new to C# and would be really grateful if someone could provide some insight on the following problem: I have written a c# app that gets the html content of a website, quite simply using a webclient. The problem is that if I run it for multiple websites I see that sometimes I get no results for some of them, like it was never connected to that website at that instance. I initially thought it was my internet connection but the same happened when I tried on a different wifi. It is worth mentioning that I have the same prob on another of my appcs when trying to connect to a webservice. My question is: does anybody know how can this be fixed? Does it have to do with the timeout time of something like that?

Thank you very much in advance

This is the code but it's not really an issue of coding:

var client = new WebClient();
try
{
  var htmlcode = client.DownloadString(site);
  int NumberOfTrues = Regex.Matches(htmlcode.ToLower(), key).Count;
}
catch (Exception)
{
   messagebox.show("could not be loaded");
}
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
user1096808
  • 253
  • 1
  • 4
  • 11
  • more detail needed when you `if I run it for multiple websites` what do you exactly do? – PUG Feb 25 '13 at 15:59
  • For example, i am searching for the word "something" in mutliple websites, so imagine I have a foreach and run the above for all websites. Then I keep the results and export it to an excel. If I increase the number of websites (like 20+) I start getting enmpty rows for some of them, and not even always the same ones! In other words, that exception above is being caught frequently and for no reason. – user1096808 Feb 25 '13 at 16:05
  • Can you post the code with your `foreach` statement. And when you export the `htmlcode` to excel. – PUG Feb 25 '13 at 16:08

1 Answers1

0

This was solved by defining the default proxy server in app config.

user1096808
  • 253
  • 1
  • 4
  • 11