Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download Script Driving Me Banannas! 1

Status
Not open for further replies.

oharab

Programmer
May 21, 2002
2,152
GB
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(&quot;DownloadFile&quot;),1)=&quot;_&quot; then
strFile = Server.MapPath(&quot;Index.asp&quot;)
strfile=left(right(strfile,12),2)
else
strfile=&quot;&quot;
end if

strFile=strfile & Request.QueryString(&quot;DownloadFile&quot;)
' File to Save As (this is the name you want to tell the browser)
Dim strFileSave: strFileSave = strfile
strfile=&quot;d:\cardiff\Emis\Excel\&quot; & strFile


' Tell Browser what the file name is, so it doesn't try to save as &quot;default.asp&quot;
Call Response.AddHeader(&quot;Content-Disposition&quot;,&quot;attachment; filename=&quot;&quot;&quot; & strFileSave & &quot;&quot;&quot;&quot;)

' Write out content-type that will FORCE user to SAVE FILE.
' &quot;image/gif&quot; will display in browser
Response.ContentType = &quot;bad/type&quot;

' Initialize File System Object
Set FSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

' 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
----------------------------------------
 
First here is a *.
Forsing a download by setting the response.contenttype I knew but with

Call Response.AddHeader(&quot;Content-Disposition&quot;,&quot;attachment; filename=&quot;&quot;&quot; & strFileSave & &quot;&quot;&quot;&quot;)

The filename of the &quot;save as&quot; window has the correct filename.

I changed your script because the downloaded file of your script was not the same as the original. Now the script depends on ADO (Microsoft Active X Data Objects 2.5 in my case).

<% Response.CacheControl = &quot;no-cache&quot; %>
<% Response.AddHeader &quot;Pragma&quot;, &quot;no-cache&quot; %>
<% Response.Expires = -1 %>
<%
' Server File (this is the REAL name of the file)
Dim strFile:
if left(Request.QueryString(&quot;DownloadFile&quot;),1)=&quot;_&quot; then
strFile = Server.MapPath(&quot;Index.asp&quot;)
strfile=left(right(strfile,12),2)
else
strfile=&quot;&quot;
end if

strFile=strfile & Request.QueryString(&quot;DownloadFile&quot;)
' File to Save As (this is the name you want to tell the browser)
Dim strFileSave: strFileSave = strfile
strfile=&quot;C:\&quot; & strFile

' to test this better make sure your asp doesn't depend on query values
strFile = &quot;C:\test.xls&quot; ' I am sure this file exist


' Tell Browser what the file name is, so it doesn't try to save as &quot;default.asp&quot;
Call Response.AddHeader(&quot;Content-Disposition&quot;,&quot;attachment; filename=&quot;&quot;&quot; & strFileSave & &quot;&quot;&quot;&quot;)

' Write out content-type that will FORCE user to SAVE FILE.
' &quot;image/gif&quot; will display in browser
Response.ContentType = &quot;bad/type&quot;

dim objStream
set objStream = server.CreateObject(&quot;ADODB.STREAM&quot;)
objStream.Type = 1
objStream.Open
objStream.LoadFromFile(strFile)
dim obj
obj = objstream.Read(objStream.Size)
Response.BinaryWrite(obj)
set obj = nothing
objStream.Close
set objstream = nothing
%>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top