—————————————————————————————————————
ASP.NET直接下载一个文件,而不是在IE中打开它
—————————————————————————————————————
Download.aspx文件:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim filename As String = Request.QueryString("filename")
Response.ContentType = "appliction/octet-stream" ‘appliction/octet-stream是MIME(Multipurpose Internet Mail Extensions)的一种,表示任何类型的文件
Response.AddHeader("Content-Disposition", "attachment;filename=" & HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8))
Response.WriteFile(filename)
Response.End()
End Sub
在另外一个文件中添加链接,如:<a href="./Download.aspx?filename=测试文件.txt">测试文件</a>
—————————————————————————————————————
ASP.NET直接下载一个文件,而不是在IE中打开它
—————————————————————————————————————
Download.aspx文件:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim filename As String = Request.QueryString("filename")
Response.ContentType = "appliction/octet-stream" ‘appliction/octet-stream是MIME(Multipurpose Internet Mail Extensions)的一种,表示任何类型的文件
Response.AddHeader("Content-Disposition", "attachment;filename=" & HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8))
Response.WriteFile(filename)
Response.End()
End Sub
在另外一个文件中添加链接,如:<a href="./Download.aspx?filename=测试文件.txt">测试文件</a>