473,473 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Strange Error - WebClient DownloadData

Hello,

I am trying to download web data into my current application. Failing
many attempts I tried to run the sample from the MS Help files with no
luck. If I create a new solution and put the sample code on a button
then it works. However, when do the same on a new form in my existing
solution then I get following error. Could there be some global
settings in my application that are causing problems?

Thanks in advance,

-Dave
Error:
-----------------------------------------------
An unhandled exception of type 'System.Net.WebException' occurred in
system.dll

Additional information: An exception occurred during a WebClient
request.
Sample Code:
-----------------------------------------------
Dim remoteUrl As String = "http://www.msn.com"

' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient

' Download the home page data.
Console.WriteLine(("Downloading " + remoteUrl))

' Downloads the Web resource and saves it into a data buffer.

' !!!!!!!!!! THIS LINE CAUSES THE ERROR !!!!!!!!!!!!!!!
Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)

' Display the downloaded data.
Dim download As String =
System.Text.Encoding.ASCII.GetString(myDatabuffer)

Console.WriteLine(download)
Console.WriteLine("Download successful.")
Nov 21 '05 #1
6 4358
Dave,

I think that for most of us that is impossible to see without the code that
generates the error.

Cor

"Dave Starman" <da*********@czechbeads.com>
Hello,

I am trying to download web data into my current application. Failing
many attempts I tried to run the sample from the MS Help files with no
luck. If I create a new solution and put the sample code on a button
then it works. However, when do the same on a new form in my existing
solution then I get following error. Could there be some global
settings in my application that are causing problems?

Thanks in advance,

-Dave
Error:
-----------------------------------------------
An unhandled exception of type 'System.Net.WebException' occurred in
system.dll

Additional information: An exception occurred during a WebClient
request.
Sample Code:
-----------------------------------------------
Dim remoteUrl As String = "http://www.msn.com"

' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient

' Download the home page data.
Console.WriteLine(("Downloading " + remoteUrl))

' Downloads the Web resource and saves it into a data buffer.

' !!!!!!!!!! THIS LINE CAUSES THE ERROR !!!!!!!!!!!!!!!
Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)

' Display the downloaded data.
Dim download As String =
System.Text.Encoding.ASCII.GetString(myDatabuffer)

Console.WriteLine(download)
Console.WriteLine("Download successful.")

Nov 21 '05 #2
Cor,

Please see my original post. The code is under the Sample Code heading.

-Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Dave.

Sorry, I had not seen it, however as you told this does work in a single
module, so where do you place it in your application?

Cor
Nov 21 '05 #4
I set up a form in a *new* application with one button and included the
code from my first post. When I click the button it returns the website
code as it should.

Next, I opened my existing (MDI) solution and added the form to the
root. I set the form as the start object (tried calling the form from
the mdi app as well) and ran the application. When I click the button I
receive the error message when the download is attempted.

-Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Dave

I tried this
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.IsMdiContainer = True
Dim frm2 As New Form2
frm2.MdiParent = Me
frm2.Show()
End Sub
///
And in Form2 in the button event the download code,

That works perfect

Cor
"Dave Starman" <da*********@czechbeads.com> schreef in bericht
news:%2****************@TK2MSFTNGP15.phx.gbl...
I set up a form in a *new* application with one button and included the
code from my first post. When I click the button it returns the website
code as it should.

Next, I opened my existing (MDI) solution and added the form to the
root. I set the form as the start object (tried calling the form from
the mdi app as well) and ran the application. When I click the button I
receive the error message when the download is attempted.

-Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #6
After further research I found a setting in the app.config. The
impersonate property was set to true. When I deleted this tag,
everything started to work.

I don't understand why that would cause a problem. Any ideas?

-Dave
------APP.CONFIG FILE causes the errors--------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<identity impersonate="true" />
</configuration>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #7

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

Similar topics

1
by: Christopher Ireland | last post by:
Hi -- I'm not looking for a definitive solution here, just some pointers in the right direction. I have a very simple UserControl in an HTML page enclosed within <object> tags virtually...
1
by: yyy | last post by:
This problem bothers me for a long time: I use WebClient.DownloadData in order to read text from an HTML document this way: WebClient c = new WebClient(); string html=...
1
by: Shiju Poyilil | last post by:
Hello everybody, I am using the the below mentioned packages for sending the mail, but when i assign the read file to a byte array " barr = wc.DownloadData(url)" I get an error "The remote...
2
by: Rags | last post by:
Hi We are creating a web application using .NET which renders some reports. The reports are created in MS Reporting Services and can be accessed by typing in a URL with the required parameters...
8
by: DEWright_CA | last post by:
Why does WebClient.DownloadFile loose my completed path? Ok, I have a function in my app then when my button is clicked it checks to see if the files come from a local drive or a http address....
4
by: Crirus | last post by:
Hi there! Fisrt the question: there is a ay to make the DownloadData when I want? I have a WebClient class I use myWebClient.DownloadData(remoteUrl) to connect to internet server All this in...
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...
0
by: aferriere | last post by:
Hi I am getting a System.Net.WebException -- >The remote server returned an error: (501) Not Implemented when I try to read the contents from...
1
by: jmk | last post by:
I'm trying to use an external SMS-service through .NET Framework 1.1 and using the webClient.DownloadData(strMessage) method. The strMessage is a string consisting the parameters to send a message,...
0
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...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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 project—planning, coding, testing,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
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.