WebClient Class throwing exception

Discussion in 'ASP .Net' started by =?Utf-8?B?RGVlcHNvbiBUaG9tYXM=?=, Jul 3, 2006.

  1. 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
     
    =?Utf-8?B?RGVlcHNvbiBUaG9tYXM=?=, Jul 3, 2006
    #1
    1. Advertising

  2. 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 ?
     
    Henrik Stidsen, Jul 3, 2006
    #2
    1. Advertising

  3. =?Utf-8?B?RGVlcHNvbiBUaG9tYXM=?=

    Joerg Jooss Guest

    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,
    --
    Joerg Jooss
     
    Joerg Jooss, Jul 9, 2006
    #3
  4. =?Utf-8?B?RGVlcHNvbiBUaG9tYXM=?=

    saliegh

    Joined:
    Jun 25, 2007
    Messages:
    1
    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
     
    saliegh, Jun 25, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KJ
    Replies:
    5
    Views:
    388
    John Saunders
    Jul 25, 2003
  2. VincentWong
    Replies:
    1
    Views:
    582
    VincentWong
    Dec 29, 2003
  3. =?Utf-8?B?VGVycnk=?=
    Replies:
    4
    Views:
    6,048
    =?Utf-8?B?VGVycnk=?=
    Jan 13, 2005
  4. =?Utf-8?B?R2xlbm4gVmVuemtl?=

    System.IO.Directoryinfo throwing exception

    =?Utf-8?B?R2xlbm4gVmVuemtl?=, Jul 25, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,729
    John Timney \(ASP.NET MVP\)
    Jul 25, 2005
  5. Tristin Davis
    Replies:
    1
    Views:
    110
    Mikael Høilund
    Jun 15, 2008
Loading...

Share This Page