关于下载路径的隐藏都是通过传递一个数据库中的ID,然后在另外一张页面通过传递的ID在数据库中读出路径。 // string destFileName = Request.QueryString[“destFileName”]!=null?Request.QueryString[“destFileName”]:””; 出处:『 漂失在蓝天下的云 』 BLOG
1、c#中实现的方法(只需要.ASPX.CS的代码就可以了)
string sel_sql=”select FileVisualPath from TabMailAttachFiles where FileID=”+Request.QueryString[“destFileName”].ToString();
string destFileName=ROA.Components.fune_commerce.Execad(sel_sql).Tables[0].Rows[0][0].ToString();
destFileName = Server.MapPath(“.”)+destFileName;
destFileName = Server.UrlDecode(destFileName);
if(File.Exists(destFileName))
{
FileInfo fi = new FileInfo(destFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
//Response.AppendHeader(“Content-Disposition”,”attachment;filename=” +HttpUtility.UrlEncode(Path.GetFileName(destFileName),System.Text.Encoding.Default));
Response.AppendHeader(“Content-Disposition”,”attachment;filename=” +HttpUtility.UrlEncode(Path.GetFileName(destFileName),System.Text.Encoding.UTF8));
Response.AppendHeader(“Content-Length”,fi.Length.ToString());
Response.ContentType=”application/octet-stream”;
Response.WriteFile(destFileName);
Response.Flush();
Response.End();
}
else
{
Response.Write(“<script langauge=javascript>alert(文件不存在!);history.go(-1);</script>”);
Response.End();
}
2、在ASP中的实现方法
<!–#include file=”conn.asp” –>
<%
Response.Buffer = true
Response.Clear
dim url
Dim fso,fl,flsize
dim Dname
Dim objStream,ContentType,flName,isre,url1
*********************************************调用时传入的下载文件名
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,1,1
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 = 1
objStream.LoadFromFile url
Select Case lcase(Right(flName, 4))
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 “.mp3”
ContentType = “audio/mpeg3”
Case “.mpg”, “mpeg”
ContentType = “video/mpeg”
Case “.rtf”
ContentType = “application/rtf”
Case “.htm”, “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-8”
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
response.Clear()
objStream.Close
Set objStream = Nothing
%>
asp和c#隐藏文件下载路径的方法_asp技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » asp和c#隐藏文件下载路径的方法_asp技巧
相关推荐
-      ASP基础教程:其它的ASP常用组件
-      ASP基础教程:学习ASP中子程序的应用
-      ASP基础教程之ASP程序对Cookie的处理
-      ASP基础教程之ASP AdRotator组件的使用
-      ADO初学者教程:ADO 通过GetString()加速脚本
-      ASP技巧实例:几行代码解决防止表单重复提交
-      ASP常见数学函数 Abs Atn Cos 等详细详解[ 来源:网页教学网 | 作者: | 时间:2007-09-12 10:57:29 | 收藏本文 ] 【大 中 小】【名称】
-      ASP基础教程之ASP AdRotator 组件的使用