|
-
June 30th, 2010, 05:33 PM
#1
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!
-
June 30th, 2010, 05:35 PM
#2
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) ;
}
--------------------------------------------------------------------------------------------------------------------------
Disclaimer - Most likely any code I have posted as an answer was most likely written free hand and may have some minor compile errors, and is merely intended to give you the idea.
-
June 30th, 2010, 05:41 PM
#3
Re: System.Net.WebException was unhandled
Thanks for the quick reply,
It now says syntax error 'try expected'
-
June 30th, 2010, 05:50 PM
#4
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?
--------------------------------------------------------------------------------------------------------------------------
Disclaimer - Most likely any code I have posted as an answer was most likely written free hand and may have some minor compile errors, and is merely intended to give you the idea.
-
June 30th, 2010, 05:55 PM
#5
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#
-
June 30th, 2010, 06:20 PM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|