關於下載路徑的隱藏都是通過傳遞一個數據庫中的ID
然後在另外一張頁面通過傳遞的ID在數據庫中讀出路徑
c#中實現的方法(只需要
ASPX
CS的代碼就可以了)
string sel_sql=
select FileVisualPath from TabMailAttachFiles where FileID=
+Request
QueryString[
destFileName
]
ToString();
// string destFileName = RequestQueryString[destFileName]!=null?RequestQueryString[destFileName]:;
string destFileName=ROAComponentsfune_commerceExecad(sel_sql)Tables[]Rows[][]ToString();
destFileName = ServerMapPath()+destFileName;
destFileName = ServerUrlDecode(destFileName);
if(FileExists(destFileName))
{
FileInfo fi = new FileInfo(destFileName);
ResponseClear();
ResponseClearHeaders();
ResponseBuffer = false;
//ResponseAppendHeader(ContentDispositionattachment;filename= +HttpUtilityUrlEncode(PathGetFileName(destFileName)SystemTextEncodingDefault));
ResponseAppendHeader(ContentDispositionattachment;filename= +HttpUtilityUrlEncode(PathGetFileName(destFileName)SystemTextEncodingUTF));
ResponseAppendHeader(ContentLengthfiLengthToString());
ResponseContentType=application/octetstream;
ResponseWriteFile(destFileName);
ResponseFlush();
ResponseEnd();
}
else
{
ResponseWrite(<script langauge=javascript>alert(文件不存在!);historygo();</script>);
ResponseEnd();
}
在ASP中的實現方法
<!
#include file=
conn
asp
>
<%
Response
Buffer = true
Response
Clear
dim url
Dim fso
fl
flsize
dim Dname
Dim objStream
ContentType
flName
isre
url
*********************************************調用時傳入的下載文件名
m_ID=trim(request
QueryString(
ID
))
set rs=Server
CreateObject(
adodb
recordset
)
sql=
select * from dataview where xsf=true and id=
&m_ID
rs
open sql
conn
if not rs
eof then
Dname=rs(
path
)
else
Response
Write(
no found
)
Response
end
end if
rs
close:set rs=nothing
******************************************************************
If Dname<>
Then
******************************下載文件存放的服務端目錄
url=Server
MapPath(Dname)
else
Response
Write(
no found
)
Response
end
End If
Set fso=Server
CreateObject(
Scripting
FileSystemObject
)
Set fl=fso
getfile(url)
flsize=fl
size
flName=fl
name
Set fl=Nothing
Set fso=Nothing
Set objStream = Server
CreateObject(
ADODB
Stream
)
objStream
Open
objStream
Type =
objStream
LoadFromFile url
Select Case lcase(Right(flName
))
Case
asf
ContentType =
video/x
ms
asf
Case
avi
ContentType =
video/avi
Case
doc
ContentType =
application/msword
Case
zip
ContentType =
application/zip
Case
xls
ContentType =
application/vnd
ms
excel
Case
gif
ContentType =
image/gif
Case
jpg
jpeg
ContentType =
image/jpeg
Case
bmp
ContentType =
image/bmp
Case
ppt
ContentType =
application/vnd
ms
powerpoint
Case
mdb
ContentType =
application/x
msaccess
Case
wav
ContentType =
audio/wav
Case
mp
ContentType =
audio/mpeg
Case
mpg
mpeg
ContentType =
video/mpeg
Case
rtf
ContentType =
application/rtf
Case
html
ContentType =
text/html
Case
txt
ContentType =
text/plain
Case Else
ContentType =
application/octet
stream
End Select
Response
AddHeader
Content
Disposition
attachment; filename=
& flName
Response
AddHeader
Content
Length
flsize
Response
Charset =
UTF
Response
ContentType = ContentType
Response
BinaryWrite objStream
Read
Response
Flush
response
Clear()
objStream
Close
Set objStream = Nothing
%>
From:http://tw.wingwit.com/Article/program/net/201311/13313.html