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

    %>


    --

    Thank you kindly,

    Dan Sikorsky MSCS, BSCE, BAB
     
    Dan Sikorsky, Apr 20, 2004
    #1
    1. Advertising

  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



    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:#...
    > oh, forgot the link
    > http://www.darkfalz.com/1098/
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > www.Darkfalz.com
    >
    >
    > "Dan Sikorsky" <> wrote in message
    > news:...
    > > 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
    > >
    > > %>
    > >
    > >
    > > --
    > >
    > > Thank you kindly,
    > >
    > > Dan Sikorsky MSCS, BSCE, BAB
    > >
    > >
    > >
    > >

    >
    >
     
    Dan Sikorsky, Apr 21, 2004
    #2
    1. Advertising

  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.

    "Dan Sikorsky" <> wrote in message
    news:...
    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



    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:#...
    > oh, forgot the link
    > http://www.darkfalz.com/1098/
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > www.Darkfalz.com
    >
    >
    > "Dan Sikorsky" <> wrote in message
    > news:...
    > > 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
    > >
    > > %>
    > >
    > >
    > > --
    > >
    > > 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



    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:u#...
    > what "Content Type" did you put in there?
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > www.Darkfalz.com
    >
    >
    > "Dan Sikorsky" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    > > "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    > > news:#...
    > > > oh, forgot the link
    > > > http://www.darkfalz.com/1098/
    > > >
    > > > --
    > > > Curt Christianson
    > > > Owner/Lead Developer, DF-Software
    > > > www.Darkfalz.com
    > > >
    > > >
    > > > "Dan Sikorsky" <> wrote in message
    > > > news:...
    > > > > 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
    > > > >
    > > > > %>
    > > > >
    > > > >
    > > > > --
    > > > >
    > > > > Thank you kindly,
    > > > >
    > > > > Dan Sikorsky MSCS, BSCE, BAB
    > > > >
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Dan Sikorsky, Apr 21, 2004
    #4
    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. Jeffrey A. Voigt

    Possible to do a File SaveAs Dialog In ASP.NET

    Jeffrey A. Voigt, Jun 16, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    5,707
    Jeffrey A. Voigt
    Jun 17, 2004
  2. N. Shehzad
    Replies:
    2
    Views:
    840
    Andrew Morton
    Apr 22, 2010
  3. N. Shehzad

    SaveAs excel Dialog and IIS ConnectionTimeOut

    N. Shehzad, Apr 20, 2010, in forum: ASP .Net Security
    Replies:
    0
    Views:
    797
    N. Shehzad
    Apr 20, 2010
  4. Martin Mrazek
    Replies:
    0
    Views:
    173
    Martin Mrazek
    May 18, 2004
  5. Pat
    Replies:
    2
    Views:
    414
    A. Sinan Unur
    Apr 23, 2004
Loading...

Share This Page