OutputStream - save file then - redirect

Discussion in 'ASP .Net' started by mboyda, Dec 19, 2003.

  1. mboyda

    mboyda Guest

    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
     
    mboyda, Dec 19, 2003
    #1
    1. Advertising

  2. 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:...
    > 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
     
    Kevin Spencer, Dec 19, 2003
    #2
    1. Advertising

  3. "mboyda" <> wrote in message
    news:...
    > 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.
     
    Richard K Bethell, Dec 19, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mboyda

    OutputStream the redirect

    mboyda, Dec 19, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    373
    mboyda
    Dec 19, 2003
  2. André
    Replies:
    3
    Views:
    1,942
    André
    Dec 1, 2006
  3. Replies:
    2
    Views:
    3,723
  4. Sal
    Replies:
    1
    Views:
    1,040
  5. Replies:
    0
    Views:
    343
Loading...

Share This Page