【发布时间】:2014-02-27 21:40:29
【问题描述】:
下面的代码可以让我下载 Word 文档.....
Try
Response.BufferOutput = True
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/msword"
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=myfile.doc")
HttpContext.Current.Response.Write(s)
'HttpContext.Current.Response.End()
HttpContext.Current.ApplicationInstance.CompleteRequest()
HttpContext.Current.Response.Flush()
Catch ex As Exception
Response.Write(ex.Message)
End Try
但是一旦我添加了一个 UpdatePanel - 它不会下载文件并且不会产生错误?阅读后,我添加了一个触发器,并将 ControlID 值设置为开始创建 Word doc 文件的按钮。我尝试了几种代码组合,但似乎没有任何效果。有关如何缩小范围的任何帮助?我也调试过,没有错误显示。我检查了我的下载文件夹-那里什么都没有,尝试设置无缓存(Response.Cache.SetCacheability(HttpCacheability.NoCache)),但没有奏效。一旦我删除了 UpdatePanel,那么一切似乎都正常了吗?
<asp:UpdateProgress ID="ProgressUpdate" AssociatedUpdatePanelID="UpdatePanel1" runat="server">
<ProgressTemplate>
<img alt="progress" src="../images/loading.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="buttonDownloadFile" />
</Triggers>
<ContentTemplate>
..
完全迷失了这一点。谁能提出解决方法或如何解决这个问题?
【问题讨论】:
-
也许不是,但我本以为有人可能对此有答案,因为我的假设是其他人会在我之前尝试过这个 ;-)
-
这个变通办法有帮助吗? encosia.com/ajax-file-downloads-and-iframes
-
我意识到这是旧的,但我也遇到了同样的问题。错误在浏览器控制台中给出
标签: asp.net .net vb.net http updatepanel