Read binary file data code from database in ASP

Source: Internet
Author: User
Binary System | data | Database <%
driver_name1= "Driver={microsoft Access driver (*.mdb)}; Dbq=d:\ database \tree. MDB "' Root database Open statement

Dim search,rs,j
Search= "SELECT * from Files where id=" & Request.QueryString ("ID")
Set My_conn=server. CreateObject ("Adodb.connection")
My_conn.open driver_name1
Set Rs=server.createobject ("ADODB. Recordset ")
Rs. Open search,my_conn,1,3
If Rs.bof or rs.eof then
Response.Write "Error: The file cannot be found"
Response.End
End If

' Set the size and MIME type of the file
Function setfordisplay (field, ContentType)
ContentType = LCase (Trim (contentType))
nfieldsize = field. ActualSize
bytes = field. GetChunk (Nfieldsize)
Session ("Bytes") = Bytes
Session ("Type") = ContentType
End Function

Setfordisplay rs ("File"), RS ("FileType")
' Response.AddHeader ' content-disposition ', ' attachment; Filename= "& RS (" FileName ")
Response.ContentType = Session ("Type")
Response. BinaryWrite session ("Bytes")
Session ("Type") = ""
Session ("Bytes") = ""

Set rs=nothing
My_conn.close
Set my_conn=nothing
%>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.