file download

J

JD

Hello Everyone,


I am trying to set up a media kit page where when a user comes to the page
for the first time and click on the image they wish to download they are
brought to a registration page. I can get that part to work successfully for
me, but this is the part does not work the way I want it to work.

After the user has entered in their registration information the download
for the file begins, once the download is done I want them to be redirected
back to the page they came from in the site.

The code I am using is as follow(s)

response.Buffer=true
'Variables
dim sDownLoadFile
dim sParentPage
dim bParentRedirect
'Check to see if you are called directly after the user has registered or if
they
'are already registered

sDownLoadFile = request.QueryString("file")
sParentPage = request.QueryString("p")
bParentRedirect = true





'Okay, lets down the files

'--declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
'-- set absolute file location
file = "zip_files/" & sDownLoadFile
strAbsFile = Server.MapPath(file)



'-- create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'-- check to see if the file exists
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)

'-- the filename you give it will be the one that is shown
' to the users by default when they save
Response.AddHeader "Content-Disposition", "attachment; filename="
& objFile.Name
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
'-- load into the stream the file
objStream.LoadFromFile(strAbsFile)
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
response.flush
objStream.Close
Set objStream = Nothing
Set objFile = Nothing



Else 'objFSO.FileExists(strAbsFile)
Response.Clear
Response.Write("No such file exists.")
response.Write strAbsFile
End If
Set objFSO = Nothing



I have tried calling this from number of ways, from putting the code in an
external file, to putting it into a function that resides on the page where
the image resides and nothing brings me back to my page that I want them to
be brought back to. It is like once the download has begun, then that is
it....I am no longer in charge of the page and the browser window has taken
over.

If this is the case then I can explain it to the client, but if there is
another way to get this to work I would really appreciate any help. Thanks.

J. D.
 

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

Forum statistics

Threads
474,038
Messages
2,570,374
Members
47,020
Latest member
anuradha

Latest Threads

Top