Problems automating FileDownload in the axWebBrowser control in C#

519 views Asked by At

I'm working on a project trying to scrape an intranet site at my company because right now there are constraints that prohibit me from getting help on the server end of things. I'm writing a C# client using an axWebBrowser control to navigate to the page. Once on the page, there is a button control that calls a .aspx page that creates a dynamic download of a csv file from an sql query. Under normal conditions this opens a FileDownload dialog to save the csv.

I've found examples of people using the BeforeNavigate2 event to capture the e.uRL and then using the FileDownload event to override the dialog box and use WebClient to retrieve the file. This method would work fine for me except the e.uRL contains the url of the .aspx script and not the .csv file that is created dynamically.

Another suggestion I read was to parse the headers from the HTML request for the file path but when I did that I threw a 401 Unauthorized Access exception on the headers.

Lastly, and I prefer to avoid this if possible, I thought about using a win32 api call and using FindWindow and SendMessage to navigate through the default file dialog but I really don't want to create a multi-threaded application with a wait in order to do this. I cannot find an event that is fired when the FileDownload dialog box is open, only events that fire before it is opened or after it is closed.

Any ideas you might have would be great, I can start pasting code in here of what I have so far if it clarifies my explanation.

0

There are 0 answers