Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by PROKA
Development & Research Department @ Elven Soft
Posted

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.

Posted
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. :(
Development & Research Department @ Elven Soft

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...