|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
在经过全球个人PC市场占有90%的微软对asp.net不断优化与整合后,asp.net与微软自身平台的动用上更加的高效,加上asp.net在应用上非常容易上手,相信asp.net仍会是最多客户选用的脚本语言,并会在未来几年继续领跑。下载 关于下载路径的埋没都是经由过程传送一个数据库中的ID,然后在别的一张页面经由过程传送的ID在数据库中读前路径。
1、c#中完成的办法(只必要.ASPX.CS的代码就能够了)
stringsel_sql="selectFileVisualPathfromTabMailAttachFileswhereFileID="+Request.QueryString["destFileName"].ToString();
//stringdestFileName=Request.QueryString["destFileName"]!=null?Request.QueryString["destFileName"]:"";
stringdestFileName=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))
{
FileInfofi=newFileInfo(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("<scriptlangauge=javascript>alert(文件不存在!);history.go(-1);</script>");
Response.End();
}
2、在ASP中的完成办法
<!--#includefile="conn.asp"-->
<%
Response.Buffer=true
Response.Clear
dimurl
Dimfso,fl,flsize
dimDname
DimobjStream,ContentType,flName,isre,url1
*********************************************挪用时传进的下载文件名
m_ID=trim(request.QueryString("ID"))
setrs=Server.CreateObject("adodb.recordset")
sql="select*fromdataviewwherexsf=trueandid="&m_ID
rs.opensql,conn,1,1
ifnotrs.eofthen
Dname=rs("path")
else
Response.Write("nofound")
Response.end
endif
rs.close:setrs=nothing
*********************************************
IfDname""Then
******************************下载文件寄存的服务端目次
url=Server.MapPath(Dname)
else
Response.Write("nofound")
Response.end
EndIf
Setfso=Server.CreateObject("Scripting.FileSystemObject")
Setfl=fso.getfile(url)
flsize=fl.size
flName=fl.name
Setfl=Nothing
Setfso=Nothing
SetobjStream=Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type=1
objStream.LoadFromFileurl
SelectCaselcase(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"
CaseElse
ContentType="application/octet-stream"
EndSelect
Response.AddHeader"Content-Disposition","attachment;filename="&flName
Response.AddHeader"Content-Length",flsize
Response.Charset="UTF-8"
Response.ContentType=ContentType
Response.BinaryWriteobjStream.Read
Response.Flush
response.Clear()
objStream.Close
SetobjStream=Nothing
%>
出处:『漂掉在蓝世界的云』BLOG
那做企业软件是不是最好用J2EE? |
|