Access Secure files on local machine or the network drives
<%
'####### Created By Pranav Ajgaonkar
'####### 12th July 2010
'####### PSCS E-BUSINESS
'####### WWW.PSCSGLOBAL.COM
'####### Access Secure files on local machine or the network drives
'####### pranav.aj@pscsglobal.com
'###### Validate User Session
'If session("loggedIn") = True Then
'###### Demo Version
'###### Enter your File Name
'###### In the Live Version develop a function to identify the File-Name based on the User Session EMP Code
'###### Place This File in C:\
testingFilename = "testfile.pdf"
'###### File Path (Local Drive or Network Drive)
strFilePath = "C:\" & testingFilename ' & request.querystring("filename")
'#####################################
'#####################################
'######### #########
'######### Do Not Edit Below #########
'######### #########
'#####################################
'#####################################
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFilePath) Then
Set objFile = objFSO.GetFile(strFilePath)
intFileSize = objFile.Size
Set objFile = Nothing
strFileName = testingFilename ' request.querystring("filename")
strFileName = replace(testingFilename," ","-") 'replace(request.querystring("filename")," ","-")
Response.AddHeader "Content-Disposition","attachment; filename=" & strFileName
Response.ContentType = "application/x-msdownload"
Response.AddHeader "Content-Length", intFileSize
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1 'adTypeBinary
objStream.LoadFromFile strFilePath
Do While Not objStream.EOS And Response.IsClientConnected
Response.BinaryWrite objStream.Read(1024)
Response.Flush()
Loop
objStream.Close
Set objStream = Nothing
Else
Response.write "Error finding file."
End if
Set objFSO = Nothing
'End If
%>