Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File download from response.binarywrite without opening a new page 1

Status
Not open for further replies.

ESquared

Programmer
Dec 23, 2003
6,129
US
See Binary Stream from Unicode String - ADODB.Stream arguments wrong for history.

So now that I have my download-a-file code working, I have another question:

After the user has made his selections for what file he wants (think of it as a report with criteria) I would like the file download to begin immediately upon clicking a button. I know how to launch a new page which, when I change the header type and flush the buffer vanishes and turns into a file download, but I'd like to skip the "new empty browser window" step if possible.

Any ideas?
 
If you direct the user to a file download script from your current page (without opening a second screen), then what should happen is that they will see the contents of that page and then get the download/save as dialog. So basically it should never leave the page they pressed the button on.

As I mentioned in the previous thread (sorry, didn't notice you had started another for this new topic), you could easily create either an intermediary page that then uses a javascript redirect to call the actual file download script, or you could use javascript in the first page to show a message before it posts to the file download page.

Either way the browser should stay on the last HTML page you delivered to it while downloading the Excel file.

If I'm misinterpreting your request, please let me know. I'm on only coffee #1 right now, so I could be off a bit. :)

 
I'm actually already up to using a DIV and will be, when the user clicks my button, writing with javascript to its innerhtml an IFRAME which has the correct URL to get the requested data, using the URL syntax which results from a GET. I'm thinking that if I make the DIV invisible, this will make the button act as if it was downloading the file directly, rather than loading a new page.

But, before I go too far with that, I'm going to just try allowing the form to post to the same page, which offers different content depending on what's posted, of course. We'll see if the header rewrite makes the original page come back or if it is left blank or if it closes.

I have a fair amount of programming experience, so I'm pretty confident I can work *something* out. The complicated part just comes from lack of much professional ASP and web experience to simply guide me among the many choices and ways of getting the same task done.
 
Oh, reading more carefully...

I don't have a problem with keeping the original/main browser page open. I just want to skip the step where a new, blank browser window opens, which is shortly replaced with a file open/save dialog. I want to the dialog to simply appear when clicking on the button as if one had clicked on a link of a type the browser has no internal handler for and would offer the open/save dialog for immediately.
 
And I finally figured it out, which was a process of doing mostly nothing.

I set the form to action="" (some deprecate this but I haven't found a better way to do it) and as long as I write the headers right away, the new file opens in a download dialog immediately and easily, without an intermediate browser window opening, and without the existing window changing.
 
I'm glad you found that and apologize that I wasn't back to be helpful before you found the answer yourself :p

 
Is there a better way to ensure that a form on a page posts to the same location without any issues of a user tampering with the form?

How do I, server-side, determine the name of the currently running .asp file so I can include it in the definition of the client-side form?
 
I'm not sure I understand. You can get the name of the page your currently executing using Request.ServerVariables("SCRIPT_NAME") and you can get the name of the page linked or submitted from by using Request.ServerVariables("HTTP_REFERER")

 
I'll give the other star in another random thread. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top