This is where link is being placed on the asp page.......
<tr>
<td>
<table cellspacing="0" border="0" cellpadding="0" width="100%">
<tr>
<td class="InputLabel" colspan="2"></td>
</tr>
<%
If IsObject(oRsAttachments) Then
do until oRsAttachments.EOF
If oRsAttachments("AttachmentDesc") = "Original Report" Then
mInternalName = oRsAttachments("InternalName")
End If
%>
<tr>
<% ' IA 4-6-04 added the statement - 'and FinalApproval = "0"
' IA 6-17-04 modifed code to not open the file directly.
If sApproving = "1" and FinalApproval = "0" then
If Not objFs.FileExists(sSubmittedPath + "\" + oRsAttachments("InternalName")) Then
sFileNotFound = "Attachment has not been scanned yet. Please contact Mary Osborn"
End If
%>
<td nowrap valign="top"><a href="\erdb\open_file.asp?filename=<%=escape(oRsAttachments("InternalName"))%>&approved=0"><%=oRsAttachments("OriginalName")%></a></td>
<td><%=sFileNotFound%></td>
<%Else
If Not objFs.FileExists(sAttachmentPath + "\" + oRsAttachments("InternalName")) Then
sFileNotFound = "Attachment has not been scanned yet. Please contact Mary Osborn"
End If
%>
<td nowrap valign="top"><a href="\erdb\open_file.asp?filename=<%=escape(oRsAttachments("InternalName"))%>&approved=1"><%=oRsAttachments("OriginalName")%></a></td>
<td><%=sFileNotFound%></td>
<%End If%>
<td width="12"> </td>
<td valign="top"><%=oRsAttachments("AttachmentDesc")%></td>
</tr>
<tr>
<td colspan=3 height="4"> </td>
</tr>
<%
oRsAttachments.MoveNext
Loop
End If
%>
</table>
</td>
</tr>
and this is openfile.asp page.............
<%
' call downloadFile(replace(replace(Request("file"),"\",""),"/",""))
dim filename
dim approved
filename = unescape(request("filename"))
approved = request("approved")
if approved = "1" then
filename = "\erdb\documents\HdDocRepository" & "\" & filename
else
filename = "\erdb\documents\HdSubmittedDocs" & "\" & filename
end if
response.write filename
call downloadFile(filename)
'call downloadFile(replace(replace(filename,"\",""),"/",""))
function AddHeaders(strFile)
dim strFileType
dim ContentType
strFileType = lcase(Right(strFile, 4))
Select Case strFileType
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".rtf"
ContentType = "application/rtf"
Case ".pdf"
ContentType = "application/pdf"
'Added on 12/01/2005 -- Anikanchan
Case ".ppt"
ContentType ="application/ms-powerpoint"
Case Else
'Handle All Files
ContentType = "application/octet-stream"
End Select
AddHeaders = ContentType
end function
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 = FxPath(strFile)
'response.write strFilename
'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 = AddHeaders(strFilename)
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
function FxPath(path)
if instr(path,",") then
FxPath = replace(path,",","%2C")
FxPath = server.mappath(FxPath)
FxPath = replace(FxPath,"%2C",",")
else
FxPath = server.mappath(path)
end if
end function
%>