为什么 TransmitFile 不下载文件?
Why the TransmitFile is not downlaoding the file?
我正在从文件夹中下载一个文件,但我的这段代码没有下载。它不会抛出任何错误,但也不会下载。
Dim req As WebClient = New WebClient()
Dim response As HttpResponse = HttpContext.Current.Response
Dim filePath As String = "~/Downloads/MyExcelFile.xls"
response.Clear()
response.ClearContent()
response.ClearHeaders()
response.Buffer = True
response.AddHeader("Content-Disposition", "attachment;filename=Filename.extension")
'Dim data As Byte() = req.DownloadData(Server.MapPath(filePath))
'response.BinaryWrite(data)
response.TransmitFile(Server.MapPath(filePath))
'response.End()
尝试
response.WriteFile("some file");
response.Flush();
response.Close();
还要考虑 Andrew 对处理程序类型的回应 - ashx 通常更干净,使用 webform 您可能会在页面生命周期中发生其他事情。
我正在从文件夹中下载一个文件,但我的这段代码没有下载。它不会抛出任何错误,但也不会下载。
Dim req As WebClient = New WebClient()
Dim response As HttpResponse = HttpContext.Current.Response
Dim filePath As String = "~/Downloads/MyExcelFile.xls"
response.Clear()
response.ClearContent()
response.ClearHeaders()
response.Buffer = True
response.AddHeader("Content-Disposition", "attachment;filename=Filename.extension")
'Dim data As Byte() = req.DownloadData(Server.MapPath(filePath))
'response.BinaryWrite(data)
response.TransmitFile(Server.MapPath(filePath))
'response.End()
尝试
response.WriteFile("some file");
response.Flush();
response.Close();
还要考虑 Andrew 对处理程序类型的回应 - ashx 通常更干净,使用 webform 您可能会在页面生命周期中发生其他事情。