PROKA Posted July 28, 2005 Posted July 28, 2005 (edited) I am using this code to download a file 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 Response.Redirect("done.aspx") but it won't redirect him. :( See attachment for details Edited March 13, 2007 by PROKA Quote Development & Research Department @ Elven Soft
cyclonebri Posted July 29, 2005 Posted July 29, 2005 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. Quote
PROKA Posted July 30, 2005 Author Posted July 30, 2005 1. I am not allowed to use pop-ups 2. how to download a file without using the response headers 3. wha' ? Quote Development & Research Department @ Elven Soft
PROKA Posted July 31, 2005 Author Posted July 31, 2005 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. :( Quote Development & Research Department @ Elven Soft
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.