在我的网页上,我有一个按钮。当我点击它时,我希望它向浏览器发送一个文档。
这是点击事件中的代码:
Private Sub btMNCgetTemplate_Click(sender As Object, e As EventArgs) Handles btMNCgetTemplate.Click
Dim MNCid As Integer = Me.cbMNCrequestType.SelectedValue
Dim mncRT As New MinorNetworkChangeTypeOfRequests
Dim MNCrq As New MNCTypeOfRequestItem
MNCrq = mncRT.Find(MNCid)
If MNCrq IsNot Nothing Then
If MNCrq.Form.ToLower.EndsWith(".doc") Or
MNCrq.Form.ToLower.EndsWith(".docx") Then
Response.ContentType = "Application/msword"
Else
Response.ContentType = "Application/x-msexcel"
End If
Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", MNCrq.Form))
Response.TransmitFile(Server.MapPath(String.Format("~/forms/{0}", MNCrq.Form)))
Response.End()
End If
End Sub
MNCrq 对象的 Form 属性具有文件的名称。
一开始这很好,用户有一个保存文件窗口。但现在它不再工作了。当我在 Chrome 中运行该网站时,没有任何反应。当我在 IE9 中运行网站时,我在一些不是我的文件中收到以下错误消息:
Unhandled exception at line 940, column 13 in http://localhost:29226/ScriptResource.axd?
d=DbqlGCg_y1TWNdNykQXSWTqf7VMHZvfOOc8W9SvKy5VJEvrKhkNOK5JNcaIC4d76X42JcWSxljh5epK1GqlRC4_NnfoLlKD1PfZ2-dNg98DHOKlBmICo8PKGlg73PqEQJR5AdM_sf6udu_6Vkp3cg9MicDI1&t=7c776dc1
0x800a139e - Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
我在这里做错了什么?
rg,埃里克