-
1
- #1
I am currently using the enclosed script to send excel files from my intranet site to users PCs. It works fine on my machine, but not on others! Instead of downloading the filename I send to it, it tries to download the page from which it was called (usually index.asp)!
I've checked version numbers of IE (all 5.50.4522.1800) and version numbers if NT. I've tried different log in names, it will work on my computer regardless of who is logged in, but not the one next to me! I'm now at a total loss! Can anyone suggest a different way of sending these excel files to my users? (I've tried using ADODB as well, but with the same result)
Anyway, here's the script.
<%
' Constants for Reading Text File
Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Const TristateFalse = 0
Const TristateMixed = -2
Const TristateTrue = -1
Const TristateUseDefault = -2
' File System Objects
Dim FSO
Dim TS
' Server File (this is the REAL name of the file)
Dim strFile:
if left(Request.QueryString("DownloadFile"
,1)="_" then
strFile = Server.MapPath("Index.asp"
strfile=left(right(strfile,12),2)
else
strfile=""
end if
strFile=strfile & Request.QueryString("DownloadFile"
' File to Save As (this is the name you want to tell the browser)
Dim strFileSave: strFileSave = strfile
strfile="d:\cardiff\Emis\Excel\" & strFile
' Tell Browser what the file name is, so it doesn't try to save as "default.asp"
Call Response.AddHeader("Content-Disposition","attachment; filename=""" & strFileSave & """"
' Write out content-type that will FORCE user to SAVE FILE.
' "image/gif" will display in browser
Response.ContentType = "bad/type"
' Initialize File System Object
Set FSO = Server.CreateObject("Scripting.FileSystemObject"
' Open TextStream for Reading
Set TS = FSO.GetFile(strFile).OpenAsTextStream(ForReading,TristateTrue)
' TS.ReadAll DOES NOT WORK. Every Byte must be read and written individually.
' I think you can read them in Chucks, but this was easier. If you know how to
' Read chunks... go ahead, read chunks
Do While Not (TS.AtEndOfStream)
' Output MUST be BinaryWrite
Response.BinaryWrite(TS.Read(1))
Loop
' Cleanup, like all good programmers do.
TS.Close
Set TS = Nothing
Set FSO = Nothing
' You don't need this, but I like it.
Response.End
%>
Please elp!!!
Ben ----------------------------------------
Ben O'Hara
----------------------------------------
I've checked version numbers of IE (all 5.50.4522.1800) and version numbers if NT. I've tried different log in names, it will work on my computer regardless of who is logged in, but not the one next to me! I'm now at a total loss! Can anyone suggest a different way of sending these excel files to my users? (I've tried using ADODB as well, but with the same result)
Anyway, here's the script.
<%
' Constants for Reading Text File
Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Const TristateFalse = 0
Const TristateMixed = -2
Const TristateTrue = -1
Const TristateUseDefault = -2
' File System Objects
Dim FSO
Dim TS
' Server File (this is the REAL name of the file)
Dim strFile:
if left(Request.QueryString("DownloadFile"
strFile = Server.MapPath("Index.asp"
strfile=left(right(strfile,12),2)
else
strfile=""
end if
strFile=strfile & Request.QueryString("DownloadFile"
' File to Save As (this is the name you want to tell the browser)
Dim strFileSave: strFileSave = strfile
strfile="d:\cardiff\Emis\Excel\" & strFile
' Tell Browser what the file name is, so it doesn't try to save as "default.asp"
Call Response.AddHeader("Content-Disposition","attachment; filename=""" & strFileSave & """"
' Write out content-type that will FORCE user to SAVE FILE.
' "image/gif" will display in browser
Response.ContentType = "bad/type"
' Initialize File System Object
Set FSO = Server.CreateObject("Scripting.FileSystemObject"
' Open TextStream for Reading
Set TS = FSO.GetFile(strFile).OpenAsTextStream(ForReading,TristateTrue)
' TS.ReadAll DOES NOT WORK. Every Byte must be read and written individually.
' I think you can read them in Chucks, but this was easier. If you know how to
' Read chunks... go ahead, read chunks
Do While Not (TS.AtEndOfStream)
' Output MUST be BinaryWrite
Response.BinaryWrite(TS.Read(1))
Loop
' Cleanup, like all good programmers do.
TS.Close
Set TS = Nothing
Set FSO = Nothing
' You don't need this, but I like it.
Response.End
%>
Please elp!!!
Ben ----------------------------------------
Ben O'Hara
----------------------------------------