Reputation: 305
I have a classic ASP web site that needs to allow users to download a large file (CSV, 20 mb). The file is stored outside of the www root folder. I found some code examples on Stackoverflow and other web sites that send the file in chunks but can not get it to work. Both IE and chrome give an error "This webpage is not found".
Here is the entire code that I have for the asp file. What am I doing wrong?
<%@ LANGUAGE=VBScript %>
<%
s_getFile "D:\Data\Dev", "laser2.csv", "laser2"
Sub s_getFile(sPath, sfilename, sBaseName)
Response.Buffer = False
Server.ScriptTimeout = 30000
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=" & sfilename
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(sPath & "\" & sBaseName)
iSz = adoStream.Size
Response.AddHeader "Content-Length", iSz' may be required
chunk = 2048
For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next
If iSz Mod chunk > 0 Then
If Response.IsClientConnected Then
Response.BinaryWrite adoStream.Read(iSz Mod chunk)
End If
End If
adoStream.Close
Set adoStream = Nothing
Response.End
End Sub
%>
Upvotes: 2
Views: 4697
Reputation: 1
I tested many scripts but it didn't work, So I used this very simple trick and it Worked Good !
<%
strFile="MyBigFile.zip"
strURL="https://"&Request.ServerVariables("server_name")&"/MyDownloadFolder"
response.redirect ""&strURL&"/"&strFile&""
%>
Upvotes: -1
Reputation: 704
When I tried removing the following line, it works.
Response.AddHeader "Content-Length", iSz
Otherwise, I got "this webpage is not available" error (IIS not responding). I'm trying this on IIS 7.5 on Windows 7. Using Fiddler, I see that IIS adds the "Content-Length" header automatically, so you don't have to.
Here is a link to another user experiencing the same thing.
If the above doesn't work, you need to check whether the file really exists. From your code above the file should be at d:\data\dev\laser2
(no csv extension!). I tested using a wrong file name, and I got a "This webpage is not found" error. Digging deeper with Fiddler, I see the error is thrown by the ADODB.Stream component: File could not be opened.
Upvotes: 4