views:

45

answers:

1

In my .aspx page, I have an image button that when clicked I want a file to download.

When the button is clicked, it logs things to do db first.

How can I push a file for download? I don't want to stream the file via asp.net on the server-side, just let the user download the file.

Is this possible?

+1  A: 

Have the page do a redirect to the URL for the PDF. There are a few ways to do that

  1. Change the response of the ASPX page to be a HTTP 301 302 with the header Location: set to the URL of the PDF.

  2. Return HTML, but with a startup script (javascript) that sets the window.location to the URL of the PDF.

  3. Return HTML but with a META to redirect to the PDF

If you want more control of how the PDF is dealt with in the browser, you might want to write an ASHX that streams the PDF and sets headers like content-disposition.

Lou Franco
@Lou Franco: Don't you mean 302 (http://en.wikipedia.org/wiki/HTTP_302)? 301 is **moved permenantly** (http://en.wikipedia.org/wiki/HTTP_301) Response.Redirect will do that for you (http://msdn.microsoft.com/en-us/library/ms524309.aspx).
R0MANARMY