Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > HOWTO: Force the SaveAs Dialog Box For Downloads

Reply
Thread Tools

HOWTO: Force the SaveAs Dialog Box For Downloads

 
 
Dan Sikorsky
Guest
Posts: n/a
 
      04-20-2004
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




 
Reply With Quote
 
 
 
 
Dan Sikorsky
Guest
Posts: n/a
 
      04-21-2004
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:#(E-Mail Removed)...
> oh, forgot the link
> http://www.darkfalz.com/1098/
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> www.Darkfalz.com
>
>
> "Dan Sikorsky" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
 
Chris Barber
Guest
Posts: n/a
 
      04-21-2004
Google has literally hundreds of examples of 'force save as dialog ASP'.
http://www.google.co.uk/search?q=for...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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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:#(E-Mail Removed)...
> oh, forgot the link
> http://www.darkfalz.com/1098/
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> www.Darkfalz.com
>
>
> "Dan Sikorsky" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >
> >
> >

>
>




 
Reply With Quote
 
Dan Sikorsky
Guest
Posts: n/a
 
      04-21-2004
asp-unknown

--

Thank you kindly,

Dan Sikorsky MSCS, BSCE, BAB



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

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM
Setting path for file saved from IE. How to activate "SaveAs" dialog box? Martin Mrazek Javascript 0 05-18-2004 02:26 PM



Advertisments