vb 操作文件下载

前端之家收集整理的这篇文章主要介绍了vb 操作文件下载前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
    Private Sub DownLoad(ByVal filePath As String)

        Dim Fi As New FileInfo(filePath)
'filePath文件路径
        If Fi.Exists Then
            Dim fs As New FileStream(filePath,FileMode.Open)
            Dim bytes As Byte() = New Byte(CInt(fs.Length) - 1) {}
            fs.Read(bytes,bytes.Length)
            fs.Close()
            Response.ContentType = "application/octet-stream"
            Response.AddHeader("Content-Disposition","attachment; filename=" & System.Web.HttpUtility.UrlEncode("temp.xls",System.Text.Encoding.GetEncoding("utf-8")))
'temp.xls 为文件名称
            Response.BinaryWrite(bytes)
            Response.Flush()
            Response.End()
        End If

    End Sub

原文链接:https://www.f2er.com/vb/261094.html

猜你在找的VB相关文章