Private Sub DownLoadPDF(ByVal filepath As String)
Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
Dim pdfFileName As String = "Exported.pdf"
If (File.Exists(filepath)) Then
Dim downloadBytes() As Byte = File.ReadAllBytes(filepath)
pdfFileName = Path.GetFileName(filepath)
'File.Delete(Me.pdfFilePath) response.Clear()
response.AddHeader("Content-Type", "binary/octet-stream")
'response.AddHeader("Expires", "0")
'response.AddHeader("Pragma", "public")
'response.AddHeader("Pragma", "no-cache")
'response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0")
'response.AddHeader("Cache-Control", "public") If (System.Web.HttpContext.Current.Request.Browser.Browser.ToLower() = "ie") Then
pdfFileName = HttpUtility.UrlEncode(pdfFileName, System.Text.Encoding.UTF8)
End If
response.AddHeader("Content-Disposition", ("attachment; filename=" _
+ (pdfFileName + ("; size=" + downloadBytes.Length.ToString))))
response.Flush()
response.BinaryWrite(downloadBytes)
response.Flush()
response.End()
End If
End Sub网上说加上注释的那段就可以,可我始终没有成功(在pageload事件中掉改方法没有问题,但是在按钮的click事件中就会出现下载aspx页面,并提示找不到)
哪位高手指点下啊
Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
Dim pdfFileName As String = "Exported.pdf"
If (File.Exists(filepath)) Then
Dim downloadBytes() As Byte = File.ReadAllBytes(filepath)
pdfFileName = Path.GetFileName(filepath)
'File.Delete(Me.pdfFilePath) response.Clear()
response.AddHeader("Content-Type", "binary/octet-stream")
'response.AddHeader("Expires", "0")
'response.AddHeader("Pragma", "public")
'response.AddHeader("Pragma", "no-cache")
'response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0")
'response.AddHeader("Cache-Control", "public") If (System.Web.HttpContext.Current.Request.Browser.Browser.ToLower() = "ie") Then
pdfFileName = HttpUtility.UrlEncode(pdfFileName, System.Text.Encoding.UTF8)
End If
response.AddHeader("Content-Disposition", ("attachment; filename=" _
+ (pdfFileName + ("; size=" + downloadBytes.Length.ToString))))
response.Flush()
response.BinaryWrite(downloadBytes)
response.Flush()
response.End()
End If
End Sub网上说加上注释的那段就可以,可我始终没有成功(在pageload事件中掉改方法没有问题,但是在按钮的click事件中就会出现下载aspx页面,并提示找不到)
哪位高手指点下啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货