各位好,我使用Response.WriteFile方法下载EXCEL文件.代码如下:
Public Sub DownloadFile(ByVal strFileName As String, ByRef Response As HttpResponse)
Dim filePath As String Try
Response.Write("<script>alert('DownloadFile!');</script>")
filePath = "C:\tmp\"
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; FileName=" & strFileName)
'Response.Buffer = True
Response.WriteFile(filePath & strFileName)
Response.Flush()
'Response.Close()
Response.End()
Catch ex As Exception
End Try
End Sub文件可以下载到本地,但是却不能刷新客户端,即alert('DownloadFile!');脚本没有执行,请问这是什么问题呢?
Public Sub DownloadFile(ByVal strFileName As String, ByRef Response As HttpResponse)
Dim filePath As String Try
Response.Write("<script>alert('DownloadFile!');</script>")
filePath = "C:\tmp\"
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; FileName=" & strFileName)
'Response.Buffer = True
Response.WriteFile(filePath & strFileName)
Response.Flush()
'Response.Close()
Response.End()
Catch ex As Exception
End Try
End Sub文件可以下载到本地,但是却不能刷新客户端,即alert('DownloadFile!');脚本没有执行,请问这是什么问题呢?
解决方案 »
- word 打开无响应
- 请问高手们,在网页上写一个地图要用到什么???
- Datalist 的问题
- 请教各位高手:在客户端用javascript修改过options的dropdownlist控件,如何才能让它将修改后的内容回发?
- 一个简单问题,大家帮帮忙 3Q!
- treeview的使用!
- Re:实现了弹出下载确认框以后,我点击了打开按钮,它又重复弹出对话框,我再次点击才能打开,如何只显示一次对话框呢?
- webService为什么返回的数据格式是xml
- 为什么RadioButton不响应鼠标点击事件阿?
- 在asp.net中怎样控制浏览器的属性?象高度,宽度和工具条的有无
- 如何实现,权限驱动的站点地图?
- C# 中的字符串数组
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; FileName=" & strFileName)
还是用Ajax或ActiveX空件吧。
Response.Write("...");
Response.Redirect("...");
Response.WriteFile(...);
// Response....上面的程序运行的结果往往只有一个方法可以得到运行结果。
所以建议LZ不要用此方法,直接把
<script> alert('DownloadFile!'); </script>
写到客户端。
请给予解释一下其中的原因.
strScriptAdd.Append("<script>")
strScriptAdd.Append("alert('DownloadFile!');")
strScriptAdd.Append("</script>")
Page.RegisterStartupScript("btnDBAdd", strScriptAdd.ToString())
你不是不需要向页面注册一次脚本啊?
filePath = "C:\tmp\"
Response.Clear()
其中Response.Clear()了,Response.Write 遇见
Response.End()才执行。