Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewing a pdf file from db

Status
Not open for further replies.

janise

Technical User
May 25, 2003
161
US
Hello everyone and happy new year to all.
I have been scouring the internet looking for articles on how to view a pdf file stored in the database.
I used aspuploads to upload pdf files into the database but I am having problem finding materials on how to view the files and other details stored in the database.

Anytime I try opening up the pdf file, it treats the file as though I was trying to download it by giving me a download dialog box.
Basically, I am looking for a sample code to view file stored in the database along with other details.
Thanks in advance
 
Hi Janise

In case the pdf file i stored in the database try this...

' set the ContentType property
Response.ContentType = "application/pdf"
Response.Addheader "Content-Disposition", "inline; filename=file.pdf"
' send the binary data to the webbrowser
Response.BinaryWrite (rs("NameOfNameOfPdfFile"))




Otherwise try this one if only the filename and not the actual file is stored in the database

<a href=&quot;<%=rs(&quot;pdfname&quot;)%>&quot; target=&quot;self&quot;>


Regards


M
 
hi Bob2!
Thanks for the response.
What is the difference between (rs(&quot;NameOfNameOfPdfFile&quot;))
and rs(&quot;pdfname&quot;)?
The fieldnames, that is?
 
Janise

Oh, no difference at all. I refer to the same database record. I guess I made you a little confused by using different names, sorry.


Regards

M
 
would you be kind enough to look at this code and tell me what I am doing wrong, please?

<%

strConnect = &quot;dsn=jobs&quot;

' Create ADO Connection
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open strConnect

' Create Recordset
Set RecSet = Server.CreateObject(&quot;ADODB.Recordset&quot;)
RecSet.Open &quot;select id, title, filename from imagefiles &quot; , Conn, 2, 3

If Not RecSet.EOF Then
' set the ContentType property
Response.Addheader &quot;Content-Disposition&quot;, &quot;inline; filename=file.pdf&quot;
' send the binary data to the webbrowser
Response.BinaryWrite (RecSet(&quot;filename&quot;))
End If

RecSet.Close
Set RecSet = Nothing

Conn.Close
Set Conn = Nothing
%>

the database structure is thus:
contentType nvarchar(50),
fileData Image,
Filename nvarchar(50),
filesize int,
title varchar(50),
Id autoNumber,
category nvarchar(50)

What I am trying to do is display details of each record which includes fikename (pdf so users can click on it to open it up for reading), title, and category.
Please I will appreciate any additional help.

 
Hi


Start with adding this line also..

Response.ContentType = &quot;application/pdf&quot;
So it look like this..

If Not RecSet.EOF Then
Response.ContentType = &quot;application/pdf&quot;

' set the ContentType property
Response.Addheader &quot;Content-Disposition&quot;, &quot;inline; filename=&quot; & (RecSet(&quot;filename&quot;))
' send the binary data to the webbrowser
Response.BinaryWrite (RecSet(&quot;filename&quot;))
End If


Let me know if this works.



Regards


M
 
Hi,
After adding that line, I got an error that says:
file does not begin with '%pdf'

Here is latest:
Also can I display, title and category also, assuming this is working?

<%

strConnect = &quot;dsn=jobs&quot;

' Create ADO Connection
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open strConnect

Response.ContentType = &quot;application/pdf&quot;

' Create Recordset
Set RecSet = Server.CreateObject(&quot;ADODB.Recordset&quot;)
RecSet.Open &quot;select filename from imagefiles &quot; , Conn, 2, 3

If Not RecSet.EOF Then
' set the ContentType property
Response.Addheader &quot;Content-Disposition&quot;, &quot;inline; filename=file.pdf&quot;
' send the binary data to the webbrowser
Response.BinaryWrite (RecSet(&quot;filename&quot;))
End If

RecSet.Close
Set RecSet = Nothing

Conn.Close
Set Conn = Nothing
%>
 
Janice


Does this one work for you?

<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<%
' Clear out the existing HTTP header information
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

' Change the HTTP header to reflect that an image is being passed.
Response.ContentType = &quot;application/pdf&quot;

strConnect = &quot;dsn=jobs&quot;
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open strConnect

Set RecSet = Server.CreateObject(&quot;ADODB.Recordset&quot;)
RecSet.Open &quot;select filename from imagefiles &quot; , Conn, 2, 3

Response.BinaryWrite RecSet(&quot;filename&quot;)

RecSet.Close
Set RecSet = Nothing

Conn.Close
Set Conn = Nothing

Response.End
%>




Regards


M
 
Still getting the same error message.
What is so frustrating about this is that I have spent forever researching asp file uploads.
All I see is how to upload a variety of files but not how to view the files uploaded to the database.
 
Mine is pdf file, though. Should I still store that in a directory and store the path in db and still have the ability to edit the directory?

In any case, your code is working working.
I needed to change a line of code in the first page that is passing records to the that page and vavoom, it started to work.
Thank for your help and patience.
It is really appreaciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top