WebClient Class throwing exception

G

Guest

Hi,

Iam trying to use WebClient class under system.net namespace to download
files from internet via http. For that iam using DownloadFile method. But
when ever iam trying to download any file iam getting the error “"The
underlying connection was closed: Unable to connect to the remote serverâ€. My
computer is behind proxy. If iam trying to open this image via browser then
it is working.

I am pasting my code below.

string remoteUri = "http://www.deepson.com/images/";
string fileName = "uc2_large08.jpg", myStringWebResource = null;


WebClient myWebClient = new WebClient();
myStringWebResource = remoteUri + fileName;
Response.Write("<hr>Downloading File "+ fileName + " from "+
myStringWebResource );


myWebClient.DownloadFile(myStringWebResource,"C:\\inetpub\\wwwroot\\TestWebApp\\Downloaded\\"+fileName);

Response.Write("<hr>Successfully Downloaded File "+ fileName +" from "+
myStringWebResource);

When I am executing this code the file is created with 0 KB size but when
the error comes it is deleted automatically.
 
H

Henrik Stidsen

Deepson said:
Iam trying to use WebClient class under system.net namespace to download
files from internet via http. For that iam using DownloadFile method. But
when ever iam trying to download any file iam getting the error ""The
underlying connection was closed: Unable to connect to the remote server". My
computer is behind proxy. If iam trying to open this image via browser then
it is working.

Have you told the WebClient object to use the proxy ?
 
J

Joerg Jooss

Thus wrote Deepson,
Hi,

Iam trying to use WebClient class under system.net namespace to
download files from internet via http. For that iam using DownloadFile
method. But when ever iam trying to download any file iam getting the
error “"The underlying connection was closed: Unable to connect to the
remote server”. My computer is behind proxy. If iam trying to open
this image via browser then it is working.

I am pasting my code below.

string remoteUri = "http://www.deepson.com/images/";
string fileName = "uc2_large08.jpg", myStringWebResource = null;
WebClient myWebClient = new WebClient();
myStringWebResource = remoteUri + fileName;
Response.Write("<hr>Downloading File "+ fileName + " from "+
myStringWebResource );
myWebClient.DownloadFile(myStringWebResource,"C:\\inetpub\\wwwroot\\Te
stWebApp\\Downloaded\\"+fileName);

Response.Write("<hr>Successfully Downloaded File "+ fileName +"
from "+ myStringWebResource);

When I am executing this code the file is created with 0 KB size but
when the error comes it is deleted automatically.

Are you using .NET 1.x or .NET 2.0?

Cheers,
 
Joined
Jun 25, 2007
Messages
1
Reaction score
0
Any solution?

Hi All.

I am experiencing this same problem. I am using .net1.1, and not using a proxy.
The strange thing is that it works on my colleage's pc!

Thanks for the help in advance.
Saliegh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top