点击下载

来源:互联网 发布:软件测试自学教程 编辑:程序博客网 时间:2024/04/28 07:18

Dim id As String = GridView1.DataKeys(e.NewSelectedIndex).Value.ToString
        Dim ds As DataSet = dataBase.getDs("select * from tb_file where id='" & id & "'")
        Dim fileName As String = ds.Tables(0).Rows(0).Item("fileName").ToString
        Dim storePath As String = ds.Tables(0).Rows(0).Item("storePath").ToString()
     
        Dim fi As New FileInfo(storePath)  'storePath--文件的物理地址
        Response.Write(storePath)
        If fi.Exists Then
            Response.Clear()
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name))
            Response.AddHeader("Content-Length", fi.Length.ToString)
            Response.ContentType = "application/octet-stream"
            Response.Filter.Close()
            Response.WriteFile(fi.FullName)
            Response.End()
        Else
            ClientScript.RegisterClientScriptBlock(GetType(String), "", "<script>alert('文件不存在')</script>")
        End If