Byte array to stream

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

We have a regular ASP website that uses the third party ASPUpload control
for uploading files. Those files are in the byte array format, ready to be
stored into SQL Server. I need to transfer that byte array to a .Net (2.0)
DLL (through COM) and then convert it to a filestream so that I can write it
to a directory on the server. I'm having trouble figuring out how to do
that.

Anyone have some ideas on the best way to do that?

Thanks
Jon
 
Here the basic idea. I'd recommend extra checks to see if path exists,
exception handling, etc.

Public Sub CreateFileFromBytes(ByVal fileAsBytes() As Byte, ByVal
pathToWrite As String)

Dim fs As FileStream = New FileStream(pathToWrite, FileMode.CreateNew)
fs.Write(fileAsBytes, 0, fileAsBytes.Length)
fs.Flush()
fs.Close()

End Sub
 
Back
Top