Know a good article or link that we're missing? Submit it!

ASP.NET

Moderators: None (Apply to moderate this forum)
Number of threads: 1467
Number of posts: 2920

This Forum Only
Post New Thread

Report
Using Response.Write() to display Binary data Posted by NewWeb on 4 Aug 2007 at 2:24 PM
Hi, I have been working on this for over two weeks and its not working. I don't know what else to do since I'm really green at this. I'm trying to display binary data from a database using Response.Write(). Please take a look to see where I went wrong, thank you in advance for your help.


Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim DBConn As OdbcConnection

Dim DBCommand As OdbcCommand


Dim DS As New DataSet
If Not LBoxProfessions.SelectedItem Is Nothing Then
DBConn = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myDB;Database=myDB;User=myUserassword=myPW;Option=3;")

DBCommand = New OdbcCommand("Select ResumeID,Resumes,DocType from tb_content where Professions = '" & LBoxProfessions.SelectedItem.Text & "' Limit 10 Offset 10", DBConn)

DBConn.Open()

Dim AD As OdbcDataReader = DBCOmmand.ExecuteReader()

If (AD.Read()) Then

Dim contentLength As Integer = Convert.ToInt32(AD.GetBytes(0, 0, Nothing, 0, Integer.MaxValue))
Dim buffer As Byte() = New Byte(contentLength - 1) {}
AD.GetBytes(0, 0, buffer, 0, contentLength)



'Resumes is the field in the database table that holds the documents
Response.AddHeader("Content-Disposition", "attachment;filename=Resumes")

'DocType is the field that holds the mime types
Response.ContentType = DirectCast(AD("DocType"), String)

Response.BinaryWrite(buffer)
Response.End()
End If
DBConn.Close()
End If

End Sub




 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.