This code helps you to download files from IIS to client computer using ASP.Net. This code can be used for sites where users can to download files by clicking a link or button.
'Getting File name to download using Querystring
Dim objFile As New FileInfo(Path.Combine(Server.MapPath("photos"),Request.QueryString("file")))
Response.Clear()
'Adding header, this says to the client browser that which file to download More info about this header :http://www.ietf.org/rfc/rfc2183.
Response.AddHeader("Content-Disposition", "attachment; filename="& objFile.Name)
Response.AddHeader("Content-Length", objFile.Length)
Response.WriteFile(objFile.Name)
Response.End()
And you can use the code like this
Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Server.Execute("download.aspx?file="&Filename)
End Sub
Pingback: .NET Thoughts » How to Store and Retrieve files from SQL Server Database