Click to See Complete Forum and Search --> : Writing binary files in server [ASP]


akgalp
September 30th, 2008, 07:39 AM
Hello All,

I got a code snippet for writing binary files in (iis) server.

Function SaveBinaryData(FileName, ByteArray)

Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

BinaryStream.Type = 1

BinaryStream.Open
BinaryStream.Write ByteArray

BinaryStream.SaveToFile FileName, 2
End Function

filename = request.querystring("filename")
root = Server.MapPath("/test")

Response.write( root & "/" & filename)
SaveBinaryData root & "/" & filename,"ddddddddd"



But this throws error "ADODB.Stream (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." at the highlighted line.

a search didn't gave much information

any help would be appreciated.
thanks

PeejAvery
September 30th, 2008, 05:56 PM
If you are using ASP, that means you are attempting to do this at the server-side. So how come you haven't declared the server for the created object?

Set BinaryStream = Server.CreateObject("ADODB.Stream")
EDIT: And is this (http://www.motobit.com/tips/detpg_read-write-binary-files/) where you got the example?

akgalp
October 2nd, 2008, 10:40 PM
If you are using ASP, that means you are attempting to do this at the server-side. So how come you haven't declared the server for the created object?

Set BinaryStream = Server.CreateObject("ADODB.Stream")

err.. :eek: my mistake.. added it.. still error persists. :confused:


EDIT: And is this (http://www.motobit.com/tips/detpg_read-write-binary-files/) where you got the example?
yes

PeejAvery
October 3rd, 2008, 07:39 AM
That's because you are passing the string "ddddddddd" to a parameter that wants a ByteArray. You probably should be working with the second example on that webpage.