-
1
- #1
jimmythegeek
Programmer
I found some code to download files through asp, and it seems to work correctly. However, when I download any kind of text file (txt, asp, htm, etc), the file is blank when it gets to my hard drive. I checked the file on the server and it is fine, but it basically erases everything on the download. Below is the code I use, any thoughts? Thanks in advance.
==========================================================
some code ..........
on error resume next
response.Buffer = True
response.Clear
set stream = server.createObject("ADODB.Stream"
stream.Open
stream.Type = 1
set fso = Server.CreateObject("Scripting.FileSystemObject"
set f = fso.GetFile(filePath)
intFilelength = f.size
stream.LoadFromFile(filePath)
strExt = lcase(right(filePath, 4))
select case strExt
case ".txt", "csv", ".inf", ".asp", ".log", ".cls", ".dsw", ".inc", ".dsp", ".ini"
contentType = "text/plain"
case "htm"
contentType = "text/html"
case ".asf"
contentType = "video/x-ms-asf"
case ".avi"
contentType = "video/avi"
case ".doc"
contentType = "application/msword"
case ".zip"
contentType = "application/zip"
case ".xls"
contentType = "application/vnd.ms-excel"
case ".gif"
contentType = "image/gif"
case ".jpg", "jpeg"
contentType = "image/jpeg"
case ".wav"
contentType = "audio/wav"
case ".mp3"
contentType = "audio/mpeg3"
case ".mpg", "mpeg"
contentType = "video/mpeg"
case ".rtf"
contentType = "application/rtf"
case else
'Handle All Other NON-Text Files
ContentType = "application/octet-stream"
end select
with response
.AddHeader "Content-Disposition", "attachment; filename=" & f.name
.AddHeader "Content-Length", intFilelength
.CharSet = "UTF-8"
.ContentType = contentType
.BinaryWrite s.Read
.flush
end with
s.Close
set s = Nothing
====================================================
Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
==========================================================
some code ..........
on error resume next
response.Buffer = True
response.Clear
set stream = server.createObject("ADODB.Stream"
stream.Open
stream.Type = 1
set fso = Server.CreateObject("Scripting.FileSystemObject"
set f = fso.GetFile(filePath)
intFilelength = f.size
stream.LoadFromFile(filePath)
strExt = lcase(right(filePath, 4))
select case strExt
case ".txt", "csv", ".inf", ".asp", ".log", ".cls", ".dsw", ".inc", ".dsp", ".ini"
contentType = "text/plain"
case "htm"
contentType = "text/html"
case ".asf"
contentType = "video/x-ms-asf"
case ".avi"
contentType = "video/avi"
case ".doc"
contentType = "application/msword"
case ".zip"
contentType = "application/zip"
case ".xls"
contentType = "application/vnd.ms-excel"
case ".gif"
contentType = "image/gif"
case ".jpg", "jpeg"
contentType = "image/jpeg"
case ".wav"
contentType = "audio/wav"
case ".mp3"
contentType = "audio/mpeg3"
case ".mpg", "mpeg"
contentType = "video/mpeg"
case ".rtf"
contentType = "application/rtf"
case else
'Handle All Other NON-Text Files
ContentType = "application/octet-stream"
end select
with response
.AddHeader "Content-Disposition", "attachment; filename=" & f.name
.AddHeader "Content-Length", intFilelength
.CharSet = "UTF-8"
.ContentType = contentType
.BinaryWrite s.Read
.flush
end with
s.Close
set s = Nothing
====================================================
Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?