Wrox Home  
Search P2P Archive for: Go

  Return to Index  

html_code_clinic thread: Forcing IE to download PDF and Exe Files


Message #1 by "Laphan" <laphan@f...> on Tue, 3 Sep 2002 20:29:01 +0100
Hi Laphan,

Here is one way to do it using ASP:

         sFullFileName = "C:\Test.pdf"
         sFileName = "Test.pdf"
         Response.Contenttype="application/x-unknown"
         Response.Addheader "Content-Disposition","attachment; filename=" & 
chr(34) & sFileName & chr(34)
         Response.Binarywrite GetBinaryFile(sFullFileName)

The function GetBinaryFile looks like this:

Function GetBinaryFile(sFileSpec)
         Const adTypeBinary = 1
         Dim objStream
         Set objStream = Server.Createobject("ADODB.Stream")
         objStream.Open
         objStream.Type = adTypeBinary
         objStream.LoadFromFile sFileSpec
         GetBinaryFile = objStream.read
         Set objStream = Nothing
End Function

This will force the browser to pop up a Save As dialog allowing the user to 
choose a directory to save the file. sFileName will be the suggested name.....

I am sure there are other ways to do this as well, but this one has worked 
for me quite well.

HtH

Imar



At 08:29 PM 9/3/2002 +0100, you wrote:
>Hi All
>
>I don't know if this is possible, but can anybody post me some code that
>forces IE to download a PDF and/or exe file rather than try to auto-load it
>into the browser.
>
>This is so annoying and I have to include a lengthy user guide on how to
>download the files because of this auto-loading.
>
>Many thanks.
>
>Rgds
>
>
>Laphan



  Return to Index