Private Sub btnDownload_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnDownload.Click ' Find the actual file location Dim FileLoc As String = Server.MapPath(txtFileName.Text) ' Get the file Dim fs As FileStream = File.OpenRead(FileLoc) ' Flush the response buffer Response.Clear() ' Supply the download name Response.AddHeader("Content-Disposition", _ "attachment; filename=" & txtFileName.Text) ' Specify the file size (makes the download ' dialog show the progress bar) Response.AddHeader("Content-Length", fs.Length.ToString()) ' Mark this as a download Response.ContentType = "application/octet-stream" ' Send the file Dim b As Int16 = 0 Do While b > -1 b = fs.ReadByte() If b > -1 Then Response.Write(ChrW(b)) End If Loop ' And close and flush the response Response.End() End Sub |