.asp页面上文件下载代码
谁有asp页面上的文件下载代码?就是在页面里写代码。
我学jsp的。让我弄asp真有点晕啊。。
我自己也在网上荡了个。但是有问题:
erp.asp页面
<a href="../erp_xz.asp">产品帮助说明文档下载</a>
erp_xz.asp页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
Const ForReading=1
Const TristateTrue=-1 'Unicode
Const FILE_TRANSFER_SIZE=16384 '16k
'Use the following line for IIS4/PWS - this is the default for IIS5
Response.Buffer = True
Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(Path)//就是这里有问题。。。path路径不对。。。
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type", mimeType
response.AddHeader "Content-Disposition","attachment;filename="&filename
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function
Dim path, mimeType, sucess
'Server.MapPath(path)
path = "D:/公司网站/公司网站/upload/"
mimeType = "application/x-msdownload"
sucess = TransferFile(path, mimeType,"ERP.pdf")
Response.End
%>
</body>
</html>
--------------------编程问答-------------------- 帮顶
补充:.NET技术 , ASP.NET