System.Net.WebException was unhandled
Hey guys I really need some help I have spent hours trying to fiddle this code,
I have this:-
Code:
System.Net.WebClient client= new System.Net.WebClient();
client.DownloadFile("http://localhost/test.txt", string.Concat("C:/test.txt"));
ok so that works fine, but I want it so that IF the file did not exist, it would have a message box poping up saying the file could not be found rather than getting a horrible message as such:-
The remote server returned an error. (404) Not Found.
I know the file doesnt' exist when I remove it from localhost, but I want to know how to verify whether or not the file exists befpre downloading, or something to give me the ability to handle custom errors!
Cheers in advance!
Re: System.Net.WebException was unhandled
Code:
try
{
System.Net.WebClient client= new System.Net.WebClient();
client.DownloadFile("http://localhost/test.txt", string.Concat("C:/test.txt"));
}
catch(Exception ex)
{
throw new Exception("Some Pretty Message for user", ex) ;
}
Re: System.Net.WebException was unhandled
Thanks for the quick reply,
It now says syntax error 'try expected'
Re: System.Net.WebException was unhandled
Is that a compile error that you are getting? Did you make sure to get the "try" at the top?
Re: System.Net.WebException was unhandled
Hi again matt,
I have this:
Code:
try
{
System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile("http://localhost/test.txt" string.Concat("C:/test.txt"));
}
catch (Exception ex)
{
throw new Exception("error", ex);
}
I get this error now:-
Exception was unhandled in visual c#
Re: System.Net.WebException was unhandled
Just a update I managed to fix it by using the Exception Inner rather than just exception!
Cheers anyway :)