'##############################################
Dim strFileName
strFileName = "c:\test.zip"
Call DownloadFile( strFileName )
Function DownloadFile(strFile)
Dim strFileName, objFs, objAdoStream, objFile, intFilelength
strFileName = strFile
' clear the buffer
Response.Buffer = True
Response.Clear
' create stream
Set objAdoStream = Server.CreateObject("ADODB.Stream")
objAdoStream.Open
' Set as binary
objAdoStream.Type = 1
' load in the file
On Error Resume Next
' check the file exists
Set objFs = Server.CreateObject("Scripting.FileSystemObject")
If Not objFs.FileExists(strFileName) then
Response.Write("<h1>Error:</h1>" & strFileName & " does not exist<p>")
Response.End
End If
' get length of file
Set objFile = objFs.GetFile(strFileName)
intFilelength = objFile.size
objAdoStream.LoadFromFile(strFileName)
if Err.Number > 0 then
Response.Write("<h1>Error: </h1>" & Err.Description & "<p>")
Response.End
end if
' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
' output the file to the browser
Response.BinaryWrite objAdoStream.Read
Response.Flush
' tidy up
Set objFile = Nothing
Set objFs = Nothing
objAdoStream.Close
Set objAdoStream = Nothing
End Function
%>