OutputStream - save file then - redirect

M

mboyda

I have a block of code that useses outputstream to save a pdf to a
client computer. It prompts the user with the save dialog, works
great but the response finishes after the download completes. How do
I redirect the users to a new friendly page after the download
completes. The aspx page comes back with a ugly "action canceled". I
prefer not to use popup windows as alot of people are blocking them.
I just want them to click a download button, download file and
continue where they left off.

Michael

Private Sub writefile(ByVal filepath As String)

Dim iStream As System.IO.Stream
Dim buffer(10000) As Byte
Dim length As Integer
Dim dataToRead As Long
Dim filename As String = System.IO.Path.GetFileName(filepath)

iStream = New System.IO.FileStream(filepath,
System.IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)

dataToRead = iStream.Length

Response.ContentType = "APPLICATION/OCTET-STREAM"
Response.AddHeader("Content-Disposition", "attachment;
filename=" & filename)
While dataToRead > 0
If Response.IsClientConnected Then
length = iStream.Read(buffer, 0, 10000)
Response.OutputStream.Write(buffer, 0, length)
Response.Flush()

ReDim buffer(10000)
dataToRead = dataToRead - length
Else
'prevent infinite loop if user disconnects
dataToRead = -1
End If
End While

End Sub
 
K

Kevin Spencer

You can't redirect in the same response. You would have to open PDF document
in a new window to acheive your business requirement. that way, the PDF
would open in a new window, and the user could close the PDF document window
when they are finished, and continue where they left off.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
R

Richard K Bethell

mboyda said:
I have a block of code that useses outputstream to save a pdf to a
client computer. It prompts the user with the save dialog, works
great but the response finishes after the download completes. How do
I redirect the users to a new friendly page after the download
completes. The aspx page comes back with a ugly "action canceled". I
prefer not to use popup windows as alot of people are blocking them.
I just want them to click a download button, download file and
continue where they left off.

I simply leave it to the user to save the PDF file. Acrobat has had a "Save"
floppy icon in its in-browser window since version 4.0, so I set the MIME
contenttype to "application/pdf" and rely on the user to save the file. You
could use frames to preserve an onscreen navigation presence, while the PDF
file is loaded.

R.
 

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

Top