0

I'm attempting to automate a task I have of interacting with a website form to download a file.

In human terms, I select a label from a list of options, and then press a submit button. The website then automatically downloads a zip file to the downloads folder.

The actions described above have the net effect of running this code in a browser console:

$('#ListBox1').val($('#ListBox1 option:first')) && $('#Download_0').click()

My question is, how can I download this zip file by running the code from a C# program? Ideally, I would also be able to specify where the file downloads to, although I'm not sure if this is possible.

Please note, this question is not asking how to download a file using C# (see: How to download a file from a website in C# and .net - Downloading a file from a website using C#). No such file exists on the website for me to download. The resulting file is generated and downloaded automatically by the two actions above.

EDIT:

The following code does download a file, however, the file is 24kb (the zip file I'm expecting is around 8mb) and unopenable:

using (WebClient client = new WebClient())
            {
                client.DownloadFile("https://cdr.ffiec.gov/public/PWS/DownloadBulkData.aspx", AppDomain.CurrentDomain.BaseDirectory + "download.zip");
            }

EDIT2: What I'm attempting to do is download the most recent zip file available containing bulk call report data. The website selects the most recently available data automatically, but I have to manually select the type of file I want to download. As such, the web request won't be static and can't be hard-coded into the program, which is why I'm attempting to interact with the webpage.

  • `No such file exists on the website for me to download. The resulting file is generated and downloaded automatically by the two actions above.` Those two statements suggest some confusion re: what downloading a file means. There doesn't _need_ to be a file on the server for you to download. HTTP doesn't work like that. If you are hitting a web server, and downloading a payload (which is what you are doing here), then the links you provided will work. Did you try them? What happened when you tried them? Please update your post to show your attempt with a [mcve]. – mjwills Mar 08 '18 at 20:56
  • Edited post to include answer from the linked posts. Again, I need some way of running the code selecting the right option on the aspx page – Chris Bertasi Mar 08 '18 at 21:08
  • 1
    Use a program, such as [Fiddler](https://www.telerik.com/fiddler) to get the actual url that's being downloaded and duplicate the web request. – Icemanind Mar 08 '18 at 21:08
  • 1
    In Chrome Developer Tools, look at the web request (Network tab) being made to download the file. That is the thing you need to do - reproduce **that web request**. Everything else is irrelevant. – mjwills Mar 08 '18 at 21:09
  • Using Chrome Developer Tools, nothing appears in the Network tab when I initiate a download. I'll attempt with Fiddler next. However, this still wouldn't quite do what I want. From my understanding, if I was able to find that specific web request, it would download the same file every time. What I'm attempting to do is download the most recent file available from the website (so the web request will change every time new data is avalable for download) – Chris Bertasi Mar 08 '18 at 21:20
  • I'll edit the post with a longer explanation – Chris Bertasi Mar 08 '18 at 21:20
  • It seems like since the file size is less than what is expected, the issue might be on the server side. Could you post the `DownloadBulkData.aspx.cs` file? – NightOwl888 Mar 08 '18 at 22:02
  • Open the 24kb file in a hex editor or even a text editor. That will give you a massive clue, I'm suspecting a YSOD asp.net error page. – Jim W Mar 08 '18 at 22:08

0 Answers0