How to use ADODB.Stream for large files

  • Thread starter Thread starter bb2j3z
  • Start date Start date
B

bb2j3z

I am trying to take binary data and save to create a PDF. I think the
problem is the size of the data. Any ideas for a workaround? I am using
vb.net in asp.net

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

'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary

'Open the stream And write binary data To the object
BinaryStream.Open

BinaryStream.Write(ByteArray)

'Save binary data To disk
BinaryStream.SaveToFile("e:\websites\testfile.pdf')

I am getting an error: on the .Write command

Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Arguments
are of the wrong type, are out of acceptable range, or are in conflict with
one another.
 
I am trying to take binary data and save to create a PDF.   I think the
problem is the size of the data.   Any ideas for a workaround?   I amusing
vb.net in asp.net

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

  'Specify stream type - we want To save binary data.
  BinaryStream.Type = adTypeBinary

  'Open the stream And write binary data To the object
  BinaryStream.Open

  BinaryStream.Write(ByteArray)

  'Save binary data To disk
  BinaryStream.SaveToFile("e:\websites\testfile.pdf')

I am getting an error: on the .Write command

Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Arguments
are of the wrong type, are out of acceptable range, or are in conflict with
one another.

Use System.IO.FileStream class to write bytes directly into a file
http://msdn2.microsoft.com/en-us/library/system.io.filestream.aspx

It has a Write method which accepts a byte
array(http://msdn2.microsoft.com/en-us/library/
system.io.filestream.write(VS.80).aspx)

Example:

Dim byteData() As Byte

Dim oFileStream As System.IO.FileStream
oFileStream = New System.IO.FileStream("testfile.pdf",
System.IO.FileMode.Create)
oFileStream.Write(byteData, 0, byteData.Length)
oFileStream.Close()
 
Back
Top