webBrowser and autodownload file

  • Thread starter Thread starter kackson
  • Start date Start date
K

kackson

Hi,

Please direct me if this is the wrong group to ask.

I'm writing a c# program to visit website and autodownload files that
may be prompted.
For example, I visit http://www.mytestwebsite.com and the page will
prompt with a somefile.csv. I would like my program to autodownload
whatever maybe the file and then parse it for info I'm interested.

My code is

webBrowser.Navigate("http://mytestwebsite.com");

I'm stuck here because after that, the browser will pop out a window to
ask to save the file. How to make the poping of window go away
automatically and directly store and parse the file?

A million thanks.
 
Instead of doing this through the web browser, you should use the
HttpWebRequest and HttpWebResponse classes. They will allow you to download
the content of the site without having to deal with a user interface.

Hope this helps.
 
Thank you.
I used HttpWebRequest and HttpWebResponse and it works. But the result
is not consistent. The problem is beating the wits out of me and
appreciate any advise.

When I tried websiteA, I am able to get the download working.
When I tried websiteB, I am unable to get the download working.
The error is
//
An unhandled exception of type 'System.Net.WebException' occurred in
System.dll
Additional information: The underlying connection was closed: An
unexpected error occurred on a receive.
//

If I run the same program at different location (e.g.in my office vs.
at home), at times both websiteA and websiteB works, yet at times only
websiteA works.

I have not have any success in locating the cause of the above error.

Could it be something special about the network at different location?
or what could be the other possible cause? Any pointers are much
appreciated.

Instead of doing this through the web browser, you should use the
HttpWebRequest and HttpWebResponse classes. They will allow you to download
the content of the site without having to deal with a user interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

Please direct me if this is the wrong group to ask.

I'm writing a c# program to visit website and autodownload files that
may be prompted.
For example, I visit http://www.mytestwebsite.com and the page will
prompt with a somefile.csv. I would like my program to autodownload
whatever maybe the file and then parse it for info I'm interested.

My code is

webBrowser.Navigate("http://mytestwebsite.com");

I'm stuck here because after that, the browser will pop out a window to
ask to save the file. How to make the poping of window go away
automatically and directly store and parse the file?

A million thanks.
 
Back
Top