HOWTO: Force the SaveAs Dialog Box For Downloads

D

Dan Sikorsky

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

%>
 
D

Dan Sikorsky

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
 
C

Chris Barber

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
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top