943,960 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 4577
  • C# RSS
Jun 4th, 2009
0

On-the-fly automated file download

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
adamf07 is offline Offline
7 posts
since Jun 2009
Jun 5th, 2009
0

Re: On-the-fly automated file download

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.

C# Syntax (Toggle Plain Text)
  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.
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jun 5th, 2009
0

Re: On-the-fly automated file download

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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
adamf07 is offline Offline
7 posts
since Jun 2009
Jun 5th, 2009
0

Re: On-the-fly automated file download

So what exactly initiates the download? It comes from javascript? You might have to just parse the javascript. Sendkeys would be a cop out
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jun 5th, 2009
0

Re: On-the-fly automated file download

Click to Expand / Collapse  Quote originally posted by Tekmaven ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
adamf07 is offline Offline
7 posts
since Jun 2009
Jan 22nd, 2010
0
Re: On-the-fly automated file download
try something like this. I send the key strokes using SendKeys.SendWait... to put in a file name for an upload control.
so look for the DocumentCompleted event once it does that or you click the link to get the file just set a timer to like 5 sec. then send the string and then your done.
C# Syntax (Toggle Plain Text)
  1. path_file = (HtmlElement)getElement(myDoc, "path", "name");
  2. if ((string)path_file.GetAttribute("type") == "file")
  3. {
  4.  
  5. path_file.Focus();
  6. filenameArray = fld_fileName.Split('\\');
  7. for (int i = 0; i < 5000; i++)
  8. {
  9. }
  10. SendKeys.SendWait(" " + fld_fileName + "{ENTER}");
  11. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
artin102 is offline Offline
1 posts
since Jan 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Help with download/save
Next Thread in C# Forum Timeline: Problem updating Excel sheet from C#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC