?
Solved

asp.net PDF from database???

Posted on 2005-04-04
8
Medium Priority
?
266 Views
Last Modified: 2010-04-07
I have a database that holds a couple pdfs as oledb objects.  When I select everything from the table holding the pdf's how do I then display a pdf on the page or in a new page from the dataset???
0
Comment
Question by:macros14
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:davidlars99
ID: 13702665
I don't know what your current setup is for the database but this is how you would do it from hard drive


<%@ Import Namespace="System.IO" %>
<%@ Page Language="VB" Debug="true" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
Dim MyFileStream As FileStream
Dim FileSize As Long

MyFileStream = New FileStream(MapPath("mypdfdocument.pdf"), FileMode.Open)
FileSize = MyFileStream.Length

Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

Response.ContentType = "application/pdf"
Response.OutputStream.Write(Buffer, 0, FileSize)
Response.Flush()
Response.Close()

%>
</BODY>
</HTML>
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13702722
eventualy you would use "Stream" class instead of "FileStream" and keep in mind that when you'll be creating a datareader you must do this for performance's sake

Dim rdr as SqlDataReader=cmd.ExecuteReader(CommandBehavior.SequentialAccess)

"CommandBehavior.SequentialAccess" is recommended when selecting BLOB data from the database
0
 
LVL 2

Expert Comment

by:dwcorwith
ID: 13703253
You will need Adobe Reader on the webserver as well?  I'm not sure of this however worth checking if its not working for you.
regards,
dwcorwith
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:macros14
ID: 13703729
I need to know how to stream the bytes out of my dataset field rather then from a file path.  Any suggestions or another option??
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13703827
<%@ Import Namespace="System.IO" %>
<%@ Page Language="VB" Debug="true" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
Dim MyFileStream As Stream
Dim FileSize As Long

MyFileStream = New Stream(dataset_field)
FileSize = MyFileStream.Length

Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

Response.ContentType = "application/pdf"
Response.OutputStream.Write(Buffer, 0, FileSize)
Response.Flush()
Response.Close()

%>
</BODY>
</HTML>
0
 
LVL 1

Author Comment

by:macros14
ID: 13706917
I get this error for instantiating the filestream

c:\inetpub\wwwroot\Church\pdf.aspx.vb(49): 'New' cannot be used on a class that is declared 'MustInherit'.
0
 
LVL 13

Accepted Solution

by:
davidlars99 earned 2000 total points
ID: 13707170
my mistake, instead of "Stream" use "BinaryReader"
0
 
LVL 1

Author Comment

by:macros14
ID: 13729024
Also get an error when it is loading saying the pdf is invalid, must have ole object header on it.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question