可以在超链接处,链向此页,传递文件地址(filename),在load事件里面用到下面代码
Try
'在此处放置初始化页的用户代码
Dim strFileName As String = Request.QueryString("FileName")
Dim toDownload As System.IO.FileInfo = New System.IO.FileInfo(Server.UrlDecode(strFileName))
Const ChunkSize As Long = 10000'一次取多少字节
Dim buffer(ChunkSize) As Byte
Response.Clear()
Dim iStream As System.IO.FileStream = System.IO.File.OpenRead(strFileName)
Dim dataLengthToRead As Long = iStream.Length
Dim tempfileName As String
tempfileName = HttpUtility.UrlEncode(toDownload.Name)'改变中文文件名乱码问题
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=" & tempfileName)
While dataLengthToRead > 0 AndAlso Response.IsClientConnected
Dim lengthRead As Integer = _
iStream.Read(buffer, 0, ChunkSize)'读取
Response.OutputStream.Write(buffer, 0, lengthRead)'写到头里面
Response.Flush()
dataLengthToRead = dataLengthToRead - lengthRead
End While
Response.Close()
Catch ex As Exception
Response.Close()
End Try