2014-02-15 145 views
2

我已經寫在傳統的ASP網站 一個頁面創建了一個從SQL數據庫,並將其存儲在一個「點擊這裏」鏈接將其下載到一起的根目錄.CSV文件用戶PC經典ASP代碼下載.csv文件

它已經很好的工作了很多年,並且在下載小文件時仍然工作正常,但是現在當下載.csv文件時出現「無法顯示此頁」錯誤(在這個例子)的一些785條記錄

代碼是非常短的下面與一個私人小組,下載

<%@Language="VBScript"%> 

<%Reponse.Buffer = True%> 
<% 
On Error Resume Next 
Dim strPath 
strPath = CStr(Request.QueryString("File")) 
'-- do some basic error checking for the QueryString 
If strPath = "" Then 
    Response.Clear 
Response.Write("No file specified.") 
Response.End 
ElseIf InStr(strPath, "..") > 0 Then 
Response.Clear 
Response.Write("Illegal folder location.") 
Response.End 
ElseIf Len(strPath) > 1024 Then 
Response.Clear 
Response.Write("Folder path too long.") 
Response.End 
Else 
Call DownloadFile(strPath) 
End If 

Private Sub DownloadFile(file) 
'--declare variables 
Dim strAbsFile 
Dim strFileExtension 
Dim objFSO 
Dim objFile 
Dim objStream 
'-- set absolute file location 
strAbsFile = Server.MapPath(file) 
'-- create FSO object to check if file exists and get properties 
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 
    Response.Clear 
    '-- the filename you give it will be the one that is shown 
    ' to the users by default when they save 
    Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name 
    Response.AddHeader "Content-Length", objFile.Size 
    Response.ContentType = "application/octet-stream" 
    Set objStream = Server.CreateObject("ADODB.Stream") 
    objStream.Open 
    '-- set as binary 
    objStream.Type = 1 
    Response.CharSet = "UTF-8" 
    '-- load into the stream the file 
    objStream.LoadFromFile(strAbsFile) 
    '-- send the stream in the response 
    Response.BinaryWrite(objStream.Read) 
    objStream.Close 
    Set objStream = Nothing 
    Set objFile = Nothing 
Else 'objFSO.FileExists(strAbsFile) 
    Response.Clear 
    Response.Write("No such file exists.") 
End If 
Set objFSO = Nothing 
End Sub 
%> 

因此,一些在最近幾個月

已經改變

好哦建議大加讚賞提前

感謝

+0

會檢查你的服務器配置並沒有改變。是否有升級等?您要檢查的值是'AspMaxRequestEntityAllowed',它將默認爲200 KB,這可以解釋爲什麼某些工作和其他工作不成功,默認情況下超過200 KB的任何內容都將失敗。如何配置這取決於您運行的是哪個版本的IIS。 – Lankymart

回答

0

可能需要你的IIS版本和配置幫助,但我知道IIS6推出了4MB限制的BinaryWrite 。嘗試以塊的形式發送文件。

<% Response.Buffer = False %> 
... 
With Server.CreateObject("ADODB.Stream") 
    .Open 
    .Type = 1 
    .LoadFromFile strPath 

    ' Send 256K chunks... 
    Const intChunkSize = 262144 

    Do While Response.IsClientConnected And (.Position < .Size) 
     Response.BinaryWrite .Read(intChunkSize) 
    Loop 

    .Close 
End With