Hi there,
The following function lets the user download the file. Use this function in a separate include file and call this function to force popup window for user to download the file to client machine.
Code:
<%
function downloadFile(strFile)
' make sure you are on the latest MDAC version for this to work
' -------------------------------------------------------------
' get full path of specified file
'strFilename = server.MapPath(strFile)
strFilename = server.MapPath(Session("downloadPath") & strFile)
' clear the buffer
Response.Buffer = True
Response.Clear
' create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open
' set as binary
s.Type = 1
' load in the file
on error resume next
' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if
' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err 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=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush
' tidy up
s.Close
Set s = Nothing
end function
%>
Just before calling this function, you should update the database and increment the DownloadCount field by 1
Code:
' Opening record set with a adOpenStatic cursor (the 3) and in UPDATE mode (the 3)
rsDC.Open cmdDC, , 3, 3
rsDC("DownLoadCount") = rsDC("DownLoadCount") + 1
rsDC.Update
' the following line calls the Download File function
call downloadFile(replace(replace(fileName,"\",""),"/","")
This should have given you an idea of how to go about.
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection