Re: download files with ASP VBScript
From: PeterB (peter_at_data.se)
Date: 02/09/05
- Next message: atx: "Re: How to automatically submit a form via IE?"
- Previous message: PeterB: "download files with ASP VBScript"
- In reply to: PeterB: "download files with ASP VBScript"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 9 Feb 2005 18:19:44 +0100
I changed to a Win2003 server and the script runs but sometimes I don't get
the entire file! It works sometimes, and especially larger files fail to
download at all or download a small part of the file.
I also had to change the script to be able to handle larger files. But my
main problem now is that the size of the original file and the downloaded
file doesn't match!
The code for larger file download:
Response.Buffer = False
Server.ScriptTimeout = 30000
chunk = 2048
iSz = adoStream.Size
'Response.ContentType = "application/asp-unknown" ' arbitrary
Response.ContentType = "octet-stream" '"application/zip"
Response.AddHeader "Content-Disposition", "attachment; filename=" &
fFileName
Response.AddHeader "Content-Length", iSz
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 objStream.Read(iSz Mod chunk)
End If
End If
adoStream.Close
Set adoStream = Nothing
Any help is appreciated!
Regards,
Peter
"PeterB" <peter@data.se> skrev i meddelandet
news:uMpBJepDFHA.3492@TK2MSFTNGP12.phx.gbl...
> Hello!
>
> I have some trouble file download, using VBScript. I am using my local IIS
> server (5.1) on my WinXP Pro SP2 machine, could this be an issue?
>
> Are there any fail-safe code snippets that download any files from a
> non-public path?
>
> Here's my script:
>
> <%
> Dim fs, fRelPath, fFileName, fFullPath, arrPath, objFileStream
> set fs=Server.CreateObject("Scripting.FileSystemObject")
>
> sql = "select file_path from files where file_id = " &
> Request.Querystring("id")
> rs.open sql, conn ', adOpenstatic, adLockOptimistic)
>
> fRelPath = rs("file_path")
> arrPath = Split(fRelPath, "\", -1, 1)
> fFileName = arrpath(UBound(arrPath,1)) 'Last object in file array is file
> name
> fFullPath = Server.mappath(fRelPath)
>
> if fs.FileExists(fFullPath)=false then
> response.write("File not found!!<br />")
> response.write("Relative path: " & fRelPath & "<br />")
> response.write("File name: " & fFileName & "<br />")
> response.write("Full path: " & fFullPath & "<br />")
> Set fs=Nothing
> Response.End
> Else
> response.write("File found!!<br>")
> response.write("Relative path: " & fRelPath & "<br />")
> response.write("File name: " & fFileName & "<br />")
> response.write("Full path: " & fFullPath & "<br />")
> end If
>
> Set objFileStream = fs.GetFile(fFullPath)
> intFilelength = objFileStream.size 'Size of file
>
> ***** I Don't get to this line.... *******
> Response.Write( "Filesize: " & intFilelength & "<br />" )
> 'Response.End
>
> Set adoStream = CreateObject("ADODB.Stream")
> adoStream.Open
> adoStream.Type = 1 'Binary
> adoStream.LoadFromFile(fFullPath)
>
> Response.Clear
> 'Response.ContentType = "application/x-unknown" ' arbitrary
> Response.ContentType = "octet-stream" ' arbitrary
> Response.AddHeader "Content-Disposition","attachment; filename=" &
> fFileName
> 'Response.AddHeader "Content-Length", intFilelength
> Response.BinaryWrite adoStream.Read(intFilelength)
> Response.Flush
>
> adoStream.Close
> Set adoStream = Nothing
> Set objFileStream = Nothing
> Set fs = Nothing
>
> Response.End
> %>
>
>
- Next message: atx: "Re: How to automatically submit a form via IE?"
- Previous message: PeterB: "download files with ASP VBScript"
- In reply to: PeterB: "download files with ASP VBScript"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|