472,125 Members | 1,428 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

WebClient class is throwing exception

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\\"+fileNa me);

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.

--
Deepson Thomas

Jul 3 '06 #1
1 1372
Deepson Thomas wrote:
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 think you've already answered your own question. You need to set up
your browser credentials for the connection:

WebProxy ProxyObject = new WebProxy("http://194.3.3.60:80" , true);
NetworkCredential cred = new NetworkCredential("User","password");
ProxyObject.Credentials=cred;
GlobalProxySelection.Select=proxyObject ;

>
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\\"+fileNa me);

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.
Jul 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thaynann | last post: by
reply views Thread by Saverio Tedeschi | last post: by
2 posts views Thread by Deepson Thomas | last post: by
4 posts views Thread by Lehel Kovach | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.