【发布时间】:2021-02-26 05:49:50
【问题描述】:
我试图通过单击按钮从服务器下载 Excel 文件,但它没有发生。它只是执行代码,但没有进行下载。
Protected Sub btn_dwnldexcel_Click(sender As Object, e As EventArgs) Handles btn_dwnldexcel.Click
Dim fileToDownload = Server.MapPath("./Data/nd_format.xls")
''Response.ContentType = "application/octet-stream"
Response.ContentType = "application/vnd.ms-excel"
Dim cd = New ContentDisposition()
cd.Inline = False
cd.FileName = Path.GetFileName(fileToDownload)
Response.AppendHeader("Content-Disposition", cd.ToString())
Dim fileData As Byte() = System.IO.File.ReadAllBytes(fileToDownload)
Response.OutputStream.Write(fileData, 0, fileData.Length)
End Sub
任何想法都将不胜感激。
【问题讨论】:
-
你是在 Visual Studio 中运行它吗?您是否尝试在调试模式下单步执行以查看问题出在哪里?请阅读stackoverflow.com/help/how-to-ask;本网站的目的不是为您调试代码。