困扰了我好久的问题,终于得以解决
- Dim strFile As String = $your file name$
- Response.Clear()
- Response.ClearHeaders()
- Response.Charset = "GB2312"
- Response.ContentEncoding = System.Text.Encoding.UTF8
- Response.ContentType = "application/octet-stream"
- Dim fi As New FileInfo(strFile)
- Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fi.Name))
- Response.AddHeader("Content-Length", fi.Length.ToString())
- Dim arrayLength As Long = fi.Length
- Dim tmpbyte(arrayLength) As Byte
- Dim fs As FileStream = fi.OpenRead()
- While fs.Read(tmpbyte, 0, CInt(arrayLength)) > 0
- Response.BinaryWrite(tmpbyte)
- Response.Flush()
- End While
- fs.Close()
- Response.End()
本文介绍了一种使用ASP.NET进行文件下载的方法。通过设置HTTP响应头并读取文件内容到内存,最终将文件以二进制形式发送到客户端,实现了高效稳定的文件下载功能。

被折叠的 条评论
为什么被折叠?



