请大家帮我看一看,先谢谢了

xhlin 2004-12-21 09:28:17
我要在asp页面中下载csv文件(已经实现)问题是页面上有闪烁的东西,函数如下
<SCRIPT language="JavaScript">
<!--
function b(){document.all.a.style.visibility = "hidden";setTimeout("c()", 500);}
function c() {document.all.a.style.visibility ="visible";setTimeout("b()", 500);}
//-->
</SCRIPT>
<body bgcolor="#FFFFFF" leftmargin="5" topmargin="5" marginwidth="0" marginheight="0" text="#222222" link="#3330A0" vlink="#3330A0" alink="#3330A0" onLoad="c()">
当我点击下载的时候,会提示我出现了运行时间错误。略过的话原页面闪烁的功能就没了,请大家告诉我该怎么处理阿
付><a href="download1.asp"><b>CSVダウンロード</b> </a>打印我是在download1.asp中实现的,如果改成><a href="download1.asp" target="_blank"><b>CSVダウンロード</b> </a>不出现错误,但是新开了一个窗口,希望高手们帮我看一看如何处理!!!!!
...全文
70 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
meizz 2004-12-21
  • 打赏
  • 举报
回复
fileList.asp:
<iframe frameborder=0 width=0 height=0 style="display: none" name="meizzFileControlDownload"></iframe>
<a href="download.asp?path=D%3A%5CWebhosting%5CClients%5Cmeizz%5Cwwwroot%5CCalendar%5FBroker%2Ehtm" target="meizzFileControlDownload">
<a href="download.asp?path=D%3A%5CWebhosting%5CClients%5Cmeizz%5Cwwwroot%5CGlobal%2Easa" target="meizzFileControlDownload">


download.asp:
<%@ Language=VBScript codepage=936 %>
<% Option Explicit %>
<%
Dim filePath, dataStream, BytesStream
filePath = request.queryString("path")
set BytesStream = server.createobject("ADODB.Stream")

With BytesStream
.Open
.Type = 2
.LoadFromFile filePath
dataStream = .Readtext
.Close
End With

set BytesStream=nothing

Response.AddHeader "content-disposition","attachment; filename="+ Mid(filePath, InStrRev(filePath, "\")+1)
Response.ContentType="application/octet-stream"
Response.BinaryWrite dataStream
%>
lnboy1003 2004-12-21
  • 打赏
  • 举报
回复
up
xhlin 2004-12-21
  • 打赏
  • 举报
回复
<%@ Language=VBScript %>
<%
Option Explicit
Response.ContentType="application/octet-stream"
Response.AddHeader "Content-Disposition","attachment; filename=test.csv"
Response.Expires=-1

Dim Rs,strSQL,g_connectstr,g_bancho,Stream
Dim i

g_connectstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PWD=bancho;Initial Catalog=luna;Data Source=."
'g_connectstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PWD=password;Initial Catalog=RentDB;Data Source=."
Set g_bancho = Server.CreateObject("ADODB.connection")
g_bancho.Open g_connectstr

Set Rs=Server.CreateObject("ADODB.Recordset")

strSQL="select "
strSQL=strSQL & " FOODID,"
strSQL=strSQL & " FOODNAME,"
strSQL=strSQL & " REALSECION,"
strSQL=strSQL & " NOWCOUNT"

strSQL=strSQL & " from material_manage "


'strSQL=strSQL & " WHERE " & Request.Form("querystr")
'Response.Write strSQL
Rs.Open strSQL,g_bancho,2,4

Set Stream=server.CreateObject("ADODB.Stream")
Stream.Type=1
Stream.Open
Stream.LoadFromFile Server.MapPath("test.csv")

If Rs.EOF Then
Response.Write "データがありません。"
Else
Response.Write """"
Response.Write "FOODID"
Response.Write ""","
Response.Write """"
Response.Write "FOODNAME"
Response.Write ""","
Response.Write """"
Response.Write "REALSECION"
Response.Write ""","
Response.Write """"
Response.Write "NOWCOUNT"
Response.Write ""","
Response.Write vbCrLf
Do until Rs.EOF
Response.Write """"
Response.Write Rs("FOODID")
Response.Write ""","
Response.Write """"
Response.Write Rs("FOODNAME")
Response.Write ""","
Response.Write """"
Response.Write Rs("REALSECION")
Response.Write ""","
Response.Write """"
Response.Write Rs("NOWCOUNT")
Response.Write ""","
Response.Write vbCrLf
Rs.MoveNext
Loop
End If

'While Not Stream.EOS
'Response.BinaryWrite Stream.Read(1024 * 64)
'Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>
<script language="javascript">
window.close();
</script>
这个是我下载页面的代码,不需要一定用response.BinaryWrite的方法输入把?请多多指点阿
xhlin 2004-12-21
  • 打赏
  • 举报
回复
to meizz(梅花雪)页面里放一个隐藏的iframe什么意思啊?我原本的页面就是在一个框架里面了阿
ghchen 2004-12-21
  • 打赏
  • 举报
回复
学习
meizz 2004-12-21
  • 打赏
  • 举报
回复
<a href="download1.asp?url=abc.csv" target="hideIframeName">
页面里放一个隐藏的 iframe , 你的 download1.asp 里用 Response.BinaryWrite 的方法输入二进制流, 客户端就会出现下载对话框了. 又不会多出一个新页. 且可以下载 .txt .htm

28,391

社区成员

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

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