I currently have a handler that when navigated to prompts the user to download a file.
I need to programmatically disable this box and allow for the file to auto download when that page is hit. Would it be easier to read that pages text and then rewrite my own file somehow?
Which would be the best approach and how would I go about doing it.
Currently I have
Sub ProcessRequest(ByVal context as HttpContext) Implements IHTTPHandler.ProcessRequest
Dim filename as String = myfile.csv
context.Response.ContentType = "text/csv"
context.Response.WriteFile(filename)
End Sub
This currently prompts the user to choose a save location and file name etc etc before starting the download.
EDIT:
As mentioned in a below response this has to be possible. Download sites automatically start downloads all the time as soon as you navigate there.
I have come across some other sites that mention IE settings could be changed? I don’t know if this could be usful in finding a solution
Yes you can. You create a form on the page, hide it and have it downloaded via javascript. It might look something like below. You set up an html form, and have it submitted by Javascript when the page has loaded. I’ve just tested in Chrome / Firefox / IE. Think about it, those download sites you see that show a message like “Your download should begin within 5 seconds, if it does not click here…”. You may want to include a direct link incase of any browser settings that may block.
Note use Response.Clear() prior to the other response code.