473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

WebClient Class 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
2 2002

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 ?

Jul 3 '06 #2
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
ne********@joergjooss.de
Jul 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: ptass | last post by:
Hi I've installed win2k3 sp1 on a machine where an openRead on any given file was previously working. After installation, I get a webException as follows... ..message "An exception occurred...
2
by: Thaynann | last post by:
Hi there, Can anyone tell me why this code appears to be throwing a WebException, and also why the files are still downloading try { imageData = webClient.DownloadData(total); MemoryStream ms...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
0
by: Saverio Tedeschi | last post by:
Hi all gurus, forgive me if I submit a 2nd post, but I'm no more able to see my question. So: I wrote an Win app with embedded FTP client (well, made some cut and paste from others' projects :-))...
1
by: Deepson Thomas | last post by:
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...
4
by: Lehel Kovach | last post by:
I'm having a problem with the WebClient object. When I post data to certain sites, it will receive a command from the webserver (object moved) and continue to the next link by downloading that. ...
1
by: Mad Scientist Jr | last post by:
For some reason I can't get a WebClient to access an outside URL from behind our firewall. The code works when it runs outside the firewall. I turned on windows authentication in the web.config...
6
by: | last post by:
I've written a very small ASP.NET page to scrape thousands of pages of content based on database IDs. It loops through a dataset to get the IDs. It worked well in testing but now I am getting an...
6
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.