Library code snippets
Sending binary data with ASP
There are situations where you need to have your ASP page sending binary data to the client. As you might now, there's no direct ASP code for reading a binary file, that's why we need to use an external component for retrieving the binary file.
But instead of writing our own component, why not using the existing ones? The ADO object, which is found on any IIS web server was written to manipulate databases, and since databases are binary files, the ADO object can read our binary files...
<%
Function getBinaryFile(strFilePath)
Dim TypeBinary, oStream
TypeBinary = 1 ' Indicates a binary file
' Create the object
Set oStream = Server.CreateObject("ADODB.Stream")
' Open our file
oStream.Open
' Retreive binary data from the file
oStream.Type = TypeBinary
oStream.LoadFromFile strFilePath
' Return the binary data to the caller
getBinaryFile = oStream.read
' Destroy the ADO object
Set oStream = Nothing
End Function
Response.BinaryWrite getBinaryFile(Server.MapPath("\my_file\thefile.bin"))
%>
Related articles
Related discussion
-
Header and Footer in Web page print
by fhajaj (4 replies)
-
help me to get simple requirement
by Slicksim (1 replies)
-
Gridview -> Template Field -> Button
by antti.simonen (1 replies)
-
Classic ASP : Page expires
by chezhian_in05 (0 replies)
-
ASP VS PHP
by paulfp (9 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Technical Support Engineer EMEA
in Reading (£50K-£50K per annum) -
Solutions Engineer
in Reading (£50K-£60K per annum)
I've altered your code just a little and it works but it doesn't exactly solve my problem. See http://flyinghands.com/a_Download0.asp
This works as long as the file being downloaded is located on the same server as the script. I have so many files I've located them on a seperate hosting service from my web site.
Here is my version:
<%@ LANGUAGE="VBScript" %>
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
<%
Function getBinaryFile(strFilePath)
Dim oStream
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = adTypeBinary
oStream.LoadFromFile strFilePath
getBinaryFile = oStream.read
Set oStream = Nothing
End Function
Dim MyFile
Dim MyPath
Dim MyServer
Dim Local
MyPath = "d/lo/10/01/"
MyFile = "d100101.mp3"
Response.AddHeader "content-disposition","inline; attachment; filename=" & chr(34) & Myfile & chr(34)
Response.ContentType = "application/x-unknown"
Response.BinaryWrite getBinaryFile(Server.MapPath(MyPath & MyFile))
%>
The Line Server.MapPath(MyPath & MyFile) resolves to the local server and I need to pass a Remote URL. Any sugestions?
Using the following two articles i managed to get the result I needed ,
http://www.developerfusion.com/show/2542
http://www.developerfusion.com/show/2235
See my other forum article for details ...
http://www.developerfusion.com/forums/topic.aspx?id=11638
I tried using oStream.mode=3 (in the article "sending binary data with Asp") but I am unable to open a word document in read/write mode. Does anyone have a solution for this?
Thanks
Pavan
This thread is for discussions of Sending binary data with ASP.