Download file, then redirect

PROKA

Junior Contributor
Joined
Sep 3, 2003
Messages
249
Location
Bucharest
I am using this code to download a file


Visual Basic:
  Response.ContentType = "application/zip"

        name = DownloadPath.Substring(DownloadPath.LastIndexOf("/") + 1, DownloadPath.LastIndexOf(".") - DownloadPath.LastIndexOf("/") - 1)
        extension = DownloadPath.Substring(DownloadPath.LastIndexOf(".") + 1, DownloadPath.Length - DownloadPath.LastIndexOf(".") - 1)

        Response.AppendHeader("Content-Disposition", "attachment; filename=" & name & "." & extension)
        Response.WriteFile(DownloadPath)
        Response.Flush()

then, I want to redirect the user to a new page, with the confirmation of the download

Visual Basic:
Response.Redirect("done.aspx")

but it won't redirect him.

:(

See attachment for details
 
Last edited:
You can't send a redirect request to the response after you've sent headers to the response object for download.
This causes an error: Cannot redirect after HTTP headers have been sent. (use try catch blocks in your code and enable tracing to see your code error out).

There are a couple of different solutions you can try. There may be other solutions but these are the ones that come to mind. I would also be interested to see an easier solution, but i've tried all the server.transfer, server.execute, writing new response headers, embedded controls and other things that I can think of for a Friday afternoon. Anyway, you can make one of these work:

1) You can have a pop-up page which downloads the file and closes itself (simple javascript). (if you are allowed to use pop-ups).

2) You can build a web-service which allows downloads of files and call the object from your webservice within the aspx page to get files from the server without using the response headers. After the file is downloaded you can then redirect the page as expected. This is more difficult but extremely solid when completed correctly.

3) You can use an I-frame, embed the page inside of a menu page and redirect on the menu page using some sort of delegate writeback to the menu once the file is downloaded from the download page. This solution is probably the worst of the three choices IMHO.
 
1. I am not allowed to use pop-ups
2. how to download a file without using the response headers
3. wha' ?
 
I am going kind of desperate here. I have to hand in a project tommorow and I have no clue of how to accomplish this redirect thing, after the download has been made. :(
 
Back
Top