file download

Discussion in 'ASP General' started by JD, Nov 17, 2005.

  1. JD

    JD Guest

    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.
    JD, Nov 17, 2005
    #1
    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. Ryan Taylor
    Replies:
    2
    Views:
    941
    Ryan Taylor
    Nov 10, 2004
  2. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,603
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  3. Sam --
    Replies:
    2
    Views:
    604
    Sam --
    Mar 17, 2005
  4. Rafal Majda
    Replies:
    5
    Views:
    2,271
    Rafal Majda
    Apr 18, 2005
  5. Brett  Kelly
    Replies:
    1
    Views:
    676
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
Loading...

Share This Page