在网页上按下一个按钮,浏览器就弹出一个下载对话框

zhuomao 2002-03-12 12:15:06
在网页上按下一个按钮,浏览器就弹出一个下载对话框
(下载文件假定是c:/inetpub/wwwroot/a.xls),该怎样实现呢?


...全文
73 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shanhe 2002-03-13
  • 打赏
  • 举报
回复
可以将文件从非web目录利用fos拷贝到web目录,然后
response.redirect temp_web_file
BrentIvan 2002-03-13
  • 打赏
  • 举报
回复
你试过我的方法吗?就是你要的
yandw 2002-03-13
  • 打赏
  • 举报
回复
我也感兴趣
BrentIvan 2002-03-12
  • 打赏
  • 举报
回复
两个文件:

test.htm
<input type="button" value="下载" onclick="window.location = 'download.asp'">


download.asp:
<%
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)
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 = "c:/inetpub/wwwroot/a.xls"
mimeType = "application/x-msdownload"
sucess = TransferFile(path, mimeType,"a.xls")
Response.End
%>
希偌 2002-03-12
  • 打赏
  • 举报
回复
<input type=button value="下载" onclick="document.execCommand('SaveAs',false,'c:\\inetpub\wwwroot\a.xls')">
reset2000 2002-03-12
  • 打赏
  • 举报
回复
<form action="down.asp">
<input type="hidden" value="<%=url%>">
<input type=submit value="下载">
</form>

down.asp
<%
dim url
url=request("url")
response.redirect url
%>
这样就可以了
srnld 2002-03-12
  • 打赏
  • 举报
回复
<input type=button value="下载" onclick="window.location.href='xxxx'
">
zhuomao 2002-03-12
  • 打赏
  • 举报
回复
顶楼的方法只是把当前的html的内容,用xls的文件名保存了。里面还是html的内容。我的意思是我在服务器上存在一个xls的文件,通过按一个按钮把它保存到客户端。
二楼的方法要把该文件先读出来,是不是有些低效,有没有更好的法子?

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧