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
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