Downloading Files stored in SQL Server

Discussion in 'ASP General' started by fibreiv, Feb 10, 2005.

  1. fibreiv

    fibreiv Guest

    I am trying to download files from my database that I uploaded to it. I can
    download bmp, txt file but have not been able to d/l pdf files. I am able to
    d/l pdf files stored in the file system but not in the database. Any help
    would be great. Here is my code, I have hard coded the file to download for
    testing purposes.

    Connect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
    ID=sa;Password=;Initial Catalog=INNB;Data Source=pompom"

    Set db = Server.CreateObject("ADODB.Connection")
    db.Open Connect

    SQL = "SELECT filesize, contenttype, filename, filedata FROM thefiles where
    id = 2"
    Set rs = db.Execute( SQL )
    If rs.EOF Then Response.End
    Response.ContentType = "application/pdf"
    Response.AddHeader "Content-Disposition", "attachment;filename=agencies.pdf"
    Response.AddHeader "Content-Length", "16863"
    Response.BinaryWrite rs("filedata")



    Thanks,
    Brett Bishop
    MCSE, MCP+I
    US Bankruptcy Court
     
    fibreiv, Feb 10, 2005
    #1
    1. Advertising

  2. fibreiv

    Guest

    fibreiv wrote:
    > I am trying to download files from my database that I uploaded to it.

    I can
    > download bmp, txt file but have not been able to d/l pdf files. I am

    able to
    > d/l pdf files stored in the file system but not in the database. Any

    help
    > would be great. Here is my code, I have hard coded the file to

    download for
    > testing purposes.
    >
    > Connect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
    > ID=sa;Password=;Initial Catalog=INNB;Data Source=pompom"
    >
    > Set db = Server.CreateObject("ADODB.Connection")
    > db.Open Connect
    >
    > SQL = "SELECT filesize, contenttype, filename, filedata FROM

    thefiles where
    > id = 2"
    > Set rs = db.Execute( SQL )
    > If rs.EOF Then Response.End
    > Response.ContentType = "application/pdf"
    > Response.AddHeader "Content-Disposition",

    "attachment;filename=agencies.pdf"
    > Response.AddHeader "Content-Length", "16863"
    > Response.BinaryWrite rs("filedata")


    So what kind of error do you get? How do you know the length is
    16863??

    When I do my binary retrieves I don't specify the length.

    Here's my generic getbinary.asp page... When a file is uploaded I store
    the mime type of the file.

    <!-- #INCLUDE VIRTUAL="/adovbs.inc" -->

    <%
    ID = Request.QueryString("ID")
    tablename=Request.QueryString("tablename")
    idfieldname=Request.QueryString("idfieldname")
    datafield=Request.QueryString("datafield")
    datacon=session("DB_CONNECTIONSTRING")
    Set con2 = Server.CreateObject("ADODB.Connection")
    Con2.open(datacon)

    mysql2="select * from " & tablename &" where "& idfieldname & "=" & ID
    Set rs2=con2.execute(mysql2)

    if not rs2.EOF then
    Response.ContentType = rs2("type_"&right(datafield,
    len(datafield)-4))
    Response.BinaryWrite(rs2(datafield))
    else
    Response.Write("Record '" + ID + "' not found.")
    end if

    rs2.Close
    %>

    <head>
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta name="Microsoft Theme" content="none, default">
    </head>
     
    , Feb 10, 2005
    #2
    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. Charlie@CBFC
    Replies:
    0
    Views:
    328
    Charlie@CBFC
    Jan 7, 2004
  2. Wardeaux
    Replies:
    7
    Views:
    407
    John Timney \(Microsoft MVP\)
    Mar 1, 2004
  3. Amol Guttal via .NET 247

    Problem in code for downloading files from web server.VIP

    Amol Guttal via .NET 247, Apr 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    435
    Amol Guttal via .NET 247
    Apr 28, 2004
  4. =?Utf-8?B?SlA=?=
    Replies:
    1
    Views:
    7,303
    Steve C. Orr [MVP, MCSD]
    Aug 10, 2005
  5. Jeppe Dige Jespersen
    Replies:
    9
    Views:
    4,669
    ihtesham
    Jun 2, 2009
Loading...

Share This Page