G
Greg
I am using the following code on a page called file.aspx
to retrieve binary files from a SQL db, but if I try to
retrieve a .exe file, it prompts me to download file.aspx
instead of [filename].exe.
<begin code>
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
' Put user code to initialize the page here' --
file.asp --
' Retrieves binary files from the database
Dim dbConn As New SqlConnection
(CCDataConnection.dbConnString)
Response.Buffer = True
' ID of the file to retrieve
Dim ID, fileSize As String
ID = Request.QueryString("id")
fileSize = Request.QueryString("size")
If Len(ID) < 1 Then
ID = 7
End If
' Recordset Object
Dim rs As SqlDataReader
Dim strSql As String
Dim sql As SqlCommand
dbConn.Open()
' opening connection
strSql = "select change_file_name,
change_file_attachment, change_file_content_type from
CHANGE_FILES where change_id_fk = " & _
ID & " AND change_file_size = '" &
fileSize & "'"
sql = New SqlCommand(strSql, dbConn)
rs = sql.ExecuteReader()
If rs.Read() Then
Response.ContentType = rs
("change_file_content_type")
Response.BinaryWrite(rs
("change_file_attachment"))
End If
rs.Close()
rs = Nothing
sql = Nothing
dbConn.Close()
dbConn = Nothing
End Sub
<end code>
Any suggestions?
Thanks,
Greg
to retrieve binary files from a SQL db, but if I try to
retrieve a .exe file, it prompts me to download file.aspx
instead of [filename].exe.
<begin code>
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
' Put user code to initialize the page here' --
file.asp --
' Retrieves binary files from the database
Dim dbConn As New SqlConnection
(CCDataConnection.dbConnString)
Response.Buffer = True
' ID of the file to retrieve
Dim ID, fileSize As String
ID = Request.QueryString("id")
fileSize = Request.QueryString("size")
If Len(ID) < 1 Then
ID = 7
End If
' Recordset Object
Dim rs As SqlDataReader
Dim strSql As String
Dim sql As SqlCommand
dbConn.Open()
' opening connection
strSql = "select change_file_name,
change_file_attachment, change_file_content_type from
CHANGE_FILES where change_id_fk = " & _
ID & " AND change_file_size = '" &
fileSize & "'"
sql = New SqlCommand(strSql, dbConn)
rs = sql.ExecuteReader()
If rs.Read() Then
Response.ContentType = rs
("change_file_content_type")
Response.BinaryWrite(rs
("change_file_attachment"))
End If
rs.Close()
rs = Nothing
sql = Nothing
dbConn.Close()
dbConn = Nothing
End Sub
<end code>
Any suggestions?
Thanks,
Greg