On-the-fly automated file download

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 7
Reputation: adamf07 is an unknown quantity at this point 
Solved Threads: 0
adamf07 adamf07 is offline Offline
Newbie Poster

On-the-fly automated file download

 
0
  #1
Jun 4th, 2009
My problem is this: I am trying to automate the download, parsing, and insertion of an excel file into a database. I have the parser and inserter done, but I can't seem to find a way to download the files automatically.

The core of the issue is that the website seems to generate the file names on the fly. So far, we have been trying to use a WebBrowser control to access the website, log in, and run the website's download script, at which point a 'save file' dialog box pops up with the file we want to save. This, however, requires human input which is the exact opposite of what automation is all about.

So, my question is this: is there a better way to do this? And if not, is there a way to access that dialog box and get the file from it?
Last edited by adamf07; Jun 4th, 2009 at 12:16 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: On-the-fly automated file download

 
0
  #2
Jun 5th, 2009
You should override the Navigating event of the browser control. You're going to have to figure out when the URL is the download url (the file name might change, but it might be in a certain path or something), and cancel the navigation, then download the url with the WebClient class.

  1. private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
  2. {
  3. //e.Url is the URL of the request
  4. //e.Cancel = true; will cancel the request in the web browser so you can handle it on your own
  5. }
Last edited by Tekmaven; Jun 5th, 2009 at 1:10 am.
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 7
Reputation: adamf07 is an unknown quantity at this point 
Solved Threads: 0
adamf07 adamf07 is offline Offline
Newbie Poster

Re: On-the-fly automated file download

 
0
  #3
Jun 5th, 2009
Thank you for the reply.

I've already tried this, but it doesn't give me the URL of the file, just the URL of the script that is sending me the file. At this point I'm looking at using wsh to automatically start the download using sendkeys and the like. It feels like a cop-out though...
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: On-the-fly automated file download

 
0
  #4
Jun 5th, 2009
So what exactly initiates the download? It comes from javascript? You might have to just parse the javascript. Sendkeys would be a cop out
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 7
Reputation: adamf07 is an unknown quantity at this point 
Solved Threads: 0
adamf07 adamf07 is offline Offline
Newbie Poster

Re: On-the-fly automated file download

 
0
  #5
Jun 5th, 2009
Originally Posted by Tekmaven View Post
So what exactly initiates the download? It comes from javascript? You might have to just parse the javascript. Sendkeys would be a cop out
I agree wholeheartedly, but I spent half of yesterday and half of today doing research and it seems that this is the only way to get what I need done. I've found a way to do it, using the win32 API. It's not pretty or elegant, but it gets the job done.

Thanks for the help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC