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
点击下载
最新推荐文章于 2022-12-08 19:10:48 发布