473,796 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.jp g", myStringWebReso urce = null;
WebClient myWebClient = new WebClient();
myStringWebReso urce = remoteUri + fileName;
Response.Write( "<hr>Downloadin g File "+ fileName + " from "+
myStringWebReso urce );
myWebClient.Dow nloadFile(myStr ingWebResource, "C:\\inetpub\\w wwroot\\TestWeb App\\Downloaded \\"+fileName) ;

Response.Write( "<hr>Successful ly Downloaded File "+ fileName +" from "+
myStringWebReso urce);

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 1471
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);
NetworkCredenti al cred = new NetworkCredenti al("User","pass word");
ProxyObject.Cre dentials=cred;
GlobalProxySele ction.Select=pr oxyObject ;

>
I am pasting my code below.

string remoteUri = "http://www.deepson.com/images/";
string fileName = "uc2_large08.jp g", myStringWebReso urce = null;
webclient myWebClient = new WebClient();
myStringWebReso urce = remoteUri + fileName;
Response.Write( "<hr>Downloadin g File "+ fileName + " from "+
myStringWebReso urce );
myWebClient.Dow nloadFile(myStr ingWebResource, "C:\\inetpub\\w wwroot\\TestWeb App\\Downloaded \\"+fileName) ;

Response.Write( "<hr>Successful ly Downloaded File "+ fileName +" from "+
myStringWebReso urce);

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
942
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 during a webclient request" .._Hresult = "-2146233079" .._COMPlusExceptionCode ="-532459699" Sorry I don't have the whole error, but this seems to be the only pertinent
2
2330
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 = new MemoryStream(imageData); Bitmap b = new Bitmap(ms); b.Save(@"C:\temp\IMAGE", ImageFormat.Tiff);
6
13305
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 = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileID.ToString() + ".pdf");
0
1837
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 :-)) to receive and send files from within the app itself. Now the server I connect to (IIS 5, W2K Svr+SP4) from 1st Jan on will allow just http/https connection, so I can no longer use FTP. I've thought to use System.Net.WebClient class and...
2
2020
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 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.
4
7784
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. The problem is, certain cookies need to be set, and the only way of doing that is not letting the WebClient automatically go on to the next GET in the background--I need to do it manually. I'm wondering if this has something to do with the...
1
6496
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 <authentication mode="Windows" /> and set up IIS to not allow anonymous access. My browser is set up to auto detect the proxy server, so IE/Firefox can access outside pages, so I added code to auto-detect the proxy server.
6
3583
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 annoying 403 error that causes the script to abort halfway through my download. I am wondering if there is a way in ASP.NET to have my code ignore 403 errors and other network errors, catch the error, and iterate to the next ID in the dataset...
6
3566
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 uncaught exception. How to catch an exception that happened before main() try { ... } catch (...) { ... } block? Is there a way?
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.