大文件的下载(分批下载)

可以在超链接处,链向此页,传递文件地址(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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值