To expand further on John's suggestion, here is some sample code I use to
retrieve an ID from a database, and stream a file which is in a directory
that isn't even accessible via the web...
------ BEGIN CODE ------
Dim fileType As String
Dim fileID As Integer
If Request.QueryString("type") Is Nothing _
Or Request.QueryString("id") Is Nothing Then
ShowNotFound()
End If
fileType = Request.QueryString("type").ToLower
fileID = Integer.Parse(Request.QueryString("id"))
Select Case fileType
Case "a"
'File requested is an attachment.
Dim fileData As DataSet
Dim inputFileName As String
Dim outputFileName As String
Dim fStream As FileStream
Dim reader As BinaryReader
ArticleManager.SetConnection(AppSettings("Database"))
fileData = ArticleManager.GetAttachmentInfo(fileID)
If fileData.Tables(0).Rows.Count = 0 Then ShowNotFound()
inputFileName = fileData.Tables(0).Rows(0)("AttachmentID")
inputFileName = "KBATT" & inputFileName & ".dat"
outputFileName = fileData.Tables(0).Rows(0)("AttachmentName")
If Not File.Exists(inputFileName) Then ShowNotFound()
fStream = New FileStream(inputFileName, FileMode.Open)
reader = New BinaryReader(fStream)
Response.ContentType = fileData.Tables(0).Rows(0)("AttachmentType")
Response.AddHeader("Content-Disposition", "attachment;filename=" &
outputFileName)
Response.AddHeader("Content-Length", fStream.Length)
Response.BinaryWrite(reader.ReadBytes(fStream.Length))
reader.Close()
Case Else
ShowNotFound()
End Select
Response.End()
End Sub
Private Sub ShowNotFound()
Dim referer As String
Response.Redirect("Error.aspx?code=404")
End Sub
--------END CODE --------
I was minding my own business when John Timney (Microsoft MVP) blurted out: