各位好,我使用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!');脚本没有执行,请问这是什么问题呢?

解决方案 »

  1.   

                                    Response.Clear()
                                    Response.ContentType   =   "application/octet-stream"
                                    Response.AddHeader("Content-Disposition",   "attachment;   FileName="   &   strFileName)
      

  2.   

    看到有很多人问类似这样的问题,用这种方法好像实现不了。
    还是用Ajax或ActiveX空件吧。
      

  3.   

    个人认为同时采用继承于Response的方法时,通常只有单个方法可用。如:// 同时存在多个Response
    Response.Write("...");
    Response.Redirect("...");
    Response.WriteFile(...);
    // Response....上面的程序运行的结果往往只有一个方法可以得到运行结果。
    所以建议LZ不要用此方法,直接把
    <script> alert('DownloadFile!'); </script> 
    写到客户端。
      

  4.   

    楼上的的没有完全理解我的意思,我是想完成文件下载以及更新客户端画面两个操作,而"Response.Write(" <script> alert('DownloadFile!'); </script> ")"只不过是想验证是否更新客户端画面而已.
    请给予解释一下其中的原因.
      

  5.   

     Dim strScriptAdd As New StringBuilder
                                strScriptAdd.Append("<script>")
                                strScriptAdd.Append("alert('DownloadFile!');")
                                strScriptAdd.Append("</script>")
                                Page.RegisterStartupScript("btnDBAdd", strScriptAdd.ToString())
    你不是不需要向页面注册一次脚本啊?
      

  6.   

     Response.Write("<script>alert('DownloadFile!');</script>")
      filePath = "C:\tmp\"
      Response.Clear()
    其中Response.Clear()了,Response.Write 遇见
    Response.End()才执行。