Returning to Default.aspx after downloading file.

M

maglev_now

After the user downloads a file from filedownload.aspx I am unable to get
them back to the default page for my site. Any suggestions?

code from filedownload.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim filename As String = DirectCast(Session("FileName"), String)
Dim filepath As String = DirectCast(Session("FilePath"), String)
Dim fullpath As String = filepath + "\" + filename
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & filename & """")
Response.Flush()
Response.WriteFile(fullpath)

End Sub

This forces the download file dialog in explorer. I get an error when
adding a redirect after Response.WriteFile(fullpath). It says you cannot
redirect after headers have been written. Dunno, please help.
 
M

Mark Fitzpatrick

Can't do it this way. The reason is, a response.redirect sends a particular
response to the browser (302 I believe) that the page has moved. This must
be done before other content is sent. Redirecting after the stream has been
sent to the browser would screw the browser up royally. I'm not sure if
server.transfer would work in this case, but it's worth a shot.
 
B

bruce barker \(sqlwork.com\)

you are allowed only one response. you can return content or a redirect, not
both. in the download link set the target to a new window. then use client
script to navigate.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top