HOWTO: Force the SaveAs Dialog Box For Downloads

Discussion in 'ASP General' started by Dan Sikorsky, Apr 20, 2004.

  1. Dan Sikorsky

    Dan Sikorsky Guest

    How do I force the "Save As" dialog box so the client can save the file into
    the folder of their choice?

    The following code should work, according to Microsoft, but downloads the
    file into the body of the browser window:
    <%

    Dim Stream

    Dim Contents

    Dim FileName

    Dim FileExt

    Const adTypeBinary = 1

    FileName = Request.QueryString("fn")

    if FileName = "" Then

    Response.Write "Filename Not specified."

    Response.End

    End if

    ' Make sure they are not requesting your

    ' code

    FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)

    Select Case UCase(FileExt)

    Case "ASP", "ASA", "ASPX", "ASAX", "MDB"

    Response.Write "Protected file Not allowed."

    Response.End

    End Select

    ' Download the file

    Response.Clear

    Response.ContentType = "application/octet-stream"

    Response.AddHeader "content-disposition", "attachment; filename=" & FileName

    Set Stream = server.CreateObject("ADODB.Stream")

    Stream.Type = adTypeBinary

    Stream.Open

    Stream.LoadFromFile Server.MapPath("uploaded") & "\" & FileName

    While Not Stream.EOS

    Response.BinaryWrite Stream.Read(1024 * 64)

    Wend

    Stream.Close

    Set Stream = Nothing

    Response.Flush

    Response.End

    %>
     
    Dan Sikorsky, Apr 20, 2004
    #1
    1. Advertisements

  2. Dan Sikorsky

    Dan Sikorsky Guest

    Your code doesn't work either ... it just loads the file in the body of the
    browser. I need something to force the Save As dialog box.

    --

    Thank you kindly,

    Dan Sikorsky MSCS, BSCE, BAB
     
    Dan Sikorsky, Apr 21, 2004
    #2
    1. Advertisements

  3. Dan Sikorsky

    Chris Barber Guest

    Google has literally hundreds of examples of 'force save as dialog ASP'.
    http://www.google.co.uk/search?q=force+save+as+dialog+asp&hl=en&ie=UTF-8&oe=UTF-8

    Here's one:
    http://tinyurl.com/2omre

    The key is to set the http headers to indicate that it is an attachment and
    then stream the content to the client.

    Chris.

    Your code doesn't work either ... it just loads the file in the body of the
    browser. I need something to force the Save As dialog box.

    --

    Thank you kindly,

    Dan Sikorsky MSCS, BSCE, BAB
     
    Chris Barber, Apr 21, 2004
    #3
  4. Dan Sikorsky

    Dan Sikorsky Guest

    asp-unknown

    --

    Thank you kindly,

    Dan Sikorsky MSCS, BSCE, BAB
     
    Dan Sikorsky, Apr 21, 2004
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.