Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > OutputStream - save file then - redirect

Reply
Thread Tools

OutputStream - save file then - redirect

 
 
mboyda
Guest
Posts: n/a
 
      12-19-2003
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
 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      12-19-2003
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.

"mboyda" <> wrote in message
news: m...
> 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



 
Reply With Quote
 
 
 
 
Richard K Bethell
Guest
Posts: n/a
 
      12-19-2003
"mboyda" <> wrote in message
news: m...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with rendering page using 'Response.Redirect' and 'Response.OutputStream' André ASP .Net 3 12-01-2006 07:20 AM
OutputStream from a URLConnection produces an OutOfMemory OutputStream from a URLConnection produces an OutOfMemory WinstonSmith_101@hotmail.com Java 2 10-25-2006 04:45 PM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM
Basic Q - Response.Redirect, all redirect to first Response.Redirect statement Sal ASP .Net Web Controls 1 05-15-2004 03:46 PM
OutputStream the redirect mboyda ASP .Net 0 12-19-2003 12:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57