© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
82 replies
YoItsTrev

✅ C# noob needs help retrying WebClient .DownloadString

I am a C# noob, so bear that in mind. I am trying to write a downloads a website sourcecode using WebClient .DownloadString. 95% of the time, it succeeds. But on occassion, it fails, and crashes the program. I have tried just about anything I could think of to try and get it to redownload the site source code anything it fails... This is the source I have currently:

static string getPageSource(string url)
{
string pageSource = "";
WebClient client = new WebClient();

pageSource = client.DownloadString(url);
if(pageSource.Length == 0)
{
pageSource = client.DownloadString(url);
}
return pageSource;
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ How to stop WebClient.DownloadString encoding apostrophies?
C#CC# / help
3y ago
C# newb Needs help
C#CC# / help
9mo ago
C# Noob needs help with (i think) simple transformation of a function
C#CC# / help
3y ago