Print Page | Close Window

FSO to Display a PDF

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=7578
Printed Date: 01 April 2026 at 1:00am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: FSO to Display a PDF
Posted By: Chattan
Subject: FSO to Display a PDF
Date Posted: 24 November 2003 at 7:03pm

Hi I am trying to display a pdf that is in a browse disabled folder on my web server.

Using an FSO Text Stream I can display a text file that is located in the same folder but when I try the pdf it displays it but it doesnt recognise it as a pdf and tries to display text so you get jibberish.

Can anyone advise how to tell the FSO to display it as a PDF. 

Cheers Chattan




Replies:
Posted By: MorningZ
Date Posted: 24 November 2003 at 7:11pm

yeah, you can't...

PDF is not plain text, so FSO Text Stream won't show anything but the compiled "jibberish"

you'll have to use a DataStream to push it to the client.....



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Chattan
Date Posted: 24 November 2003 at 7:15pm
Thanks Ive been banging my head agains that one for two days.


Posted By: MorningZ
Date Posted: 24 November 2003 at 7:26pm

just remember for down the road that the FSO Text stuff will read any file just like it was opened up in Notepad...

so jibberish in Notepad = jibberish to FSO.Text stuff



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Chattan
Date Posted: 24 November 2003 at 8:07pm

Ive only been playing with fso for the last week so its all new to me . I managed to get it to work using the following code.

<%
 Response.ContentType = "application/pdf"
 
 strFilePath = "c:/folder/file"
 
 Dim oStream
 Set oStream = Server.CreateObject("ADODB.Stream")

 oStream.Open
 oStream.Type = 1 'adTypeBinary
 
 oStream.LoadFromFile strFilePath
 
 varPdf = oStream.Read

 Response.BinaryWrite( varPdf )
 
 oStream.Close
 Set oStream = Nothing
%>

 

Know I just need to carry the link name into the fso so it knows which file to display that way I wont have to create a fso page for every indervidual pdf.

Thanks for your help.



Posted By: MorningZ
Date Posted: 24 November 2003 at 8:23pm
Originally posted by Chattan Chattan wrote:

Know I just need to carry the link name into the fso so it knows which file to display that way I wont have to create a fso page for every indervidual pdf.

is that a question or statement? lol

if its a question:

strFilePath = "c:\folder\file\" & Request.QueryString("FileName")

also might want to make sure the file exists, otherwise FSO will cough out an error

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
If FSO.FileExists( strFilePath  ) Then
    oStream.LoadFromFile strFilePath
    varPdf = oStream.Read
    Response.BinaryWrite( varPdf )
Else
    'Some sort of error handling here
End If
Set FSO = Nothing

 



-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net