By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,588 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,588 IT Pros & Developers. It's quick & easy.

Download dialog for known MIME type

P: n/a
I am writing an ASP page for downloading some files, such as jpg, doc
which are known MIME type. I want to force user save these files through
a "file download" dialog instead of open them on the IE by default. I
search the Internet and found the best way to do it is by using stream.
The following is my code for the download.asp. There are 2 problems, one
is when I use firefox and click the link to download.asp, I found the
system become slower and slower, it seems the CPU usage become very high.
Another problem is when I use the right button of my mice on the link to
download.asp, and choose "save as", it will not save the doc file, it
saves download.asp. Please help me, thanks!

'--declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
'-- set absolute file location
strAbsFile = Server.MapPath(sPath)
'-- create FSO object to check if file exists and get
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'-- check to see if the file exists
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
'-- first clear the response, and then set the
appropriate headers
'-- the filename you give it will be the one that is
' to the users by default when they save
Response.AddHeader "Content-Disposition", "attachment;
filename=" +
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
'-- load into the stream the file
'-- send the stream in the response
binData = objStream.Read
Set objStream = Nothing
Set objFile = Nothing
Else 'objFSO.FileExists(strAbsFile)
Response.Write("File does not exist!")
End If
Set objFSO = Nothing
Oct 30 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.