Hi,
I am storing a file in a blob field. I need to pass this to a .NET control as a parameter of type System.Byte[]. Is there any way to convert the blob field to a System.Byte[] type?
One way would be to write the file temporarily to disk and them use the .NET System.IO.BinaryReader class to read it back in again.
Is there anyway to do this without writing the file to disk?
Thanks
Hi,
I got this sorted using a System.IO.MemoryStream.
DEFINE VARIABLE m1 AS MEMPTR NO-UNDO.
DEFINE VARIABLE iSize AS INT NO-UNDO.
DEF VAR oMemStream AS System.IO.MemoryStream NO-UNDO.
DEF VAR ix AS INT NO-UNDO.
DEF TEMP-TABLE ttStore NO-UNDO
FIELD ttData AS BLOB.
CREATE ttStore.
COPY-LOB FILE "file" TO ttStore.ttData NO-CONVERT .
COPY-LOB ttStore.ttData TO m1 NO-CONVERT.
iSize = GET-SIZE(m1).
oMemStream = NEW System.IO.MemoryStream(iSize).
DO ix = 1 TO iSize:
oMemStream:WriteByte(GET-BYTE(m1,ix)).
END.
SET-SIZE(m1) = 0.
oMemStream:GetBuffer().
oMemStream = ?.
The oMemStream:GetBuffer() will return the System.Byte[].