Retrieving executables from SQL in ASP.NET

Discussion in 'ASP .Net' started by Greg, Nov 4, 2003.

  1. Greg

    Greg Guest

    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
    Greg, Nov 4, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Devyn

    Executables?

    Devyn, Apr 10, 2004, in forum: Perl
    Replies:
    3
    Views:
    568
    J├╝rgen Exner
    Apr 11, 2004
  2. Kaidi
    Replies:
    4
    Views:
    2,794
    Kaidi
    Jul 14, 2004
  3. Francesc Guim Bernat

    .NET executables and XML, i need help :-(

    Francesc Guim Bernat, Sep 17, 2003, in forum: C++
    Replies:
    2
    Views:
    361
    Pianoman
    Sep 19, 2003
  4. ASP.NET and Executables

    , Apr 10, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    511
    Eliyahu Goldin
    Apr 10, 2007
  5. Doug Partridge

    Running executables from ASP page

    Doug Partridge, Sep 6, 2003, in forum: ASP General
    Replies:
    2
    Views:
    84
    Bite My Bubbles
    Sep 7, 2003
Loading...

Share This Page