Function ReadBinaryFile(FileName)
Const adTypeBinary = 1
Dim BinaryStream
Set BinaryStream = Server.CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Open
BinaryStream.LoadFromFile FileName
ReadBinaryFile = BinaryStream.Read
End Function
myFile = Request.QueryString("fileName")
myExtension = mid(myFile,instr(myFile,".") + 1)
myFileType = "Text"
pathName = Request.QueryString("Path")
myPath = server.MapPath(pathName & myFile)
if myExtension = "EPS" or myExtension="GIF" or myExtension="JPG" then
myFileType = "image"
end if
if myExtension = "PDF" then
myFileType = "application"
end if
dim myStream
myStream = ReadBinaryFile(myPath)
Response.Buffer = True
Response.AddHeader "content-disposition", "attachment; filename=" & myFile
Response.AddHeader "content-length", Len(mystream)
Response.ContentType = myFileType & "/" & myExtension
Response.BinaryWrite myStream
Response.Flush
{/code]
I use this code to force a download of PDF's, EPS, GIF and JPG files from one of our applications to the client machine.
Notice the Response.AddHeader statements and the Response.ContentType.
What you are doing is sending the data to the browser, then telling the browser not to handle it as content for the browser.
The example above opens takes a file, reads it as binary data then sends it to the browser so that the browser opens a save file dialogue box.
I'm only handling PDF, EPS JPG and GIF in this example. If you want to use something else, you need to find out what to set for the different content types.
To build may have to be the slow laborious task of years. To destroy can simply be the thoughtless act of a single day.