从.net网站下载时,文件格式和扩展名与excel不匹配

时间:2017-07-24 16:25:15

标签: asp.net excel vb.net

我创建了一个ASP.net网站,后端代码在Vb中我生成了一个按钮,用于将内容保存在excel文件中,但当Excel尝试打开文件时,我收到以下消息。

*'FileName.xls'的格式和扩展名不匹配。该文件可能已损坏或不安全。除非您信任其来源,否则请勿打开它。你想打开吗?

我正在附加我的aspx.vb代码

 Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        Response.Clear()
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
        Response.Charset = ""
        Response.ContentType = "application/vnd.xls"
        Dim stringWrite As New System.IO.StringWriter()
        Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
        GridView5.RenderControl(htmlWrite)
        Response.Write(stringWrite.ToString())
        Response.[End]()
    End Sub

0 个答案:

没有答案