Home All Groups Group Topic Archive Search About

WebClient Class throwing exception

Author
3 Jul 2006 10:29 AM
Deepson Thomas
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.

--
Deepson Thomas

Author
3 Jul 2006 12:04 PM
Henrik Stidsen
Deepson Thomas wrote:

>   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 ?
Are all your drivers up to date? click for free checkup

Author
9 Jul 2006 9:17 AM
Joerg Jooss
Thus wrote Deepson,

Show quoteHide quote
> 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,
--
Joerg Jooss
news-re***@joergjooss.de

Bookmark and Share