Reply
Using BinaryWrite to display PDF - with no DLL?
Old 05-24-2005, 01:30 PM Using BinaryWrite to display PDF - with no DLL?
funkdaddu's Avatar
Web Design Snob

Posts: 636
I'm trying to show a PDF using BinaryWrite (like the tutorial here http://psacake.com/web/gj.asp ) but I don't have access to the server to make the DLL file to have this run right. Is there another way? Thanks.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
When You Register, These Ads Go Away!
Old 05-24-2005, 05:25 PM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Do you have ASP.NET available? You could do the same sort of thing in ASP.NET and not have to muck around with a component.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-24-2005, 07:44 PM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
hahahaha funny
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.
http://www.smartsoft-ng.com
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Old 05-25-2005, 09:36 AM
funkdaddu's Avatar
Web Design Snob

Posts: 636
Yeah, it's a .NET server, how would I go about doing it with that? I'm only really familiar with standard ASP.

Funny? I don't get it...
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 05-25-2005, 10:26 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
No, neither do I. If you're gonna post something, make it relevant.

Try this. Put it in a file with a .aspx extention:

Code:
<% Page Language="VB" %>
 
<script runat="server">
	Sub Page_Load
		Dim MyFileStream As FileStream
		Dim FileSize As Long
 
		MyFileStream = New FileStream("myfile.pdf", FileMode.Open)
		FileSize = MyFileStream.Length
 
		Dim Buffer(CInt(FileSize)) As Byte
		MyFileStream.Read(Buffer, 0, CInt(FileSize))
		MyFileStream.Close()
 
		Response.ContentType = "application/octet-stream"
		Response.BinaryWrite(Buffer)
	End Sub
</script>
I havn't tested it myself so it might need some tweaking. Post back here if you have any trouble.

If you want some really good documentation on what each of the functions/classes do, download the .NET SDK

http://www.microsoft.com/downloads/d...displaylang=en

There's also a load of great .NET tutorials, samples and resources at http://www.asp.net
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad

Last edited by Minaki : 05-25-2005 at 10:28 AM.
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-31-2005, 09:40 AM
funkdaddu's Avatar
Web Design Snob

Posts: 636
OK, I got ASP.NET installed (it wasn't) and now I'm getting this error:

Compiler Error Message: BC30002: Type 'FileStream' is not defined.

Source Error:


Line 3: <script runat="server">
Line 4: Sub Page_Load
Line 5: Dim MyFileStream As FileStream
Line 6: Dim FileSize As Long

I also had to put @ in front of the Page Language="VB" to get it to work. Thanks.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 05-31-2005, 10:13 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Oh yeah. You need to import the namespace. Under the <@ Page directive, put an import directive:

<%@ Import Namespace="System.IO" %>

You could also simply change Line 5:

Dim MyFileStream As System.IO.FileStream

but it's usually better to import cos you usually use things from that namespace more than once.

If you need to find out what namespace a class belongs to, download the .NET SDK, open the documentation and search for the class name (in this case, FileStream). The namespace will be shown at the bottom of the page.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-31-2005, 03:41 PM
funkdaddu's Avatar
Web Design Snob

Posts: 636
OK, this works, but according to the error I get, it needs write permission to do it. Is there a way to do it as read only? Or is that really against the nature of how BinaryWrite works? Thanks for the help on this, I appreciate it. For anyone else, this is the code I have so far... I takes the location and file name and passes it through the scrip to hide the location of the original file:

Code:
<%@ Page Language="VB" debug="true"%>
<%@ Import Namespace="System.IO" %>

<script runat="server">
        Sub Page_Load
                Dim MyFileStream As FileStream
                Dim FileSize As Long
				Dim getFile, section, mFile
				
				getFile = Request.QueryString("f")
				section = Request.QueryString("s")
				
				mFile = Server.MapPath("dlfolder/" & section & "/" & getFile)

                MyFileStream = New FileStream(mFile, FileMode.Open)
                FileSize = MyFileStream.Length
 
                Dim Buffer(CInt(FileSize)) As Byte
                MyFileStream.Read(Buffer, 0, CInt(FileSize))
                MyFileStream.Close()
 
				Response.Addheader("Content-Disposition", "inline; filename=" & getFile)
				Response.CacheControl = "public"
                Response.ContentType = "application/pdf"
                Response.BinaryWrite(Buffer)
        End Sub
</script>
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 05-31-2005, 03:57 PM
funkdaddu's Avatar
Web Design Snob

Posts: 636
Ahh I think I have it... Adding ", FileAccess.Read" to the FileStream Command set s the write permission before accessing the file. Thanks for the help.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Reply     « Reply to Using BinaryWrite to display PDF - with no DLL?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16452 seconds with 12 queries