Writing a file

  • Thread starter Thread starter Victor Rodriguez
  • Start date Start date
V

Victor Rodriguez

Is there a way to write a file from:
Dim datafile As System.IO.Stream =
Me.GetType().Assembly.GetManifestResourceStream("myassembly.filename.dbf")

To a physical file on the hard drive like "C:\filename.dbf"?

thanks in advance...

Victor
 
Victor Rodriguez said:
Is there a way to write a file from:
Dim datafile As System.IO.Stream =
Me.GetType().Assembly.GetManifestResourceStream("myassembly.filename.dbf")

To a physical file on the hard drive like "C:\filename.dbf"?

Sure - just open the output stream, and then copy a block at a time
(e.g. 8K) from the manifest resource stream to the output stream until
you've read it all.
 
Victor Rodriguez said:
Is there a way to write a file from:
Dim datafile As System.IO.Stream =
Me.GetType().Assembly.GetManifestResourceStream("myassembly.filename.dbf")

To a physical file on the hard drive like "C:\filename.dbf"?

Written from scratch and thus untested:

\\\
Imports System.IO
Imports System.Reflection
..
..
..
Dim s As Stream = _
[Assembly].GetExecutingAssembly().GetManifestResourceStream( _
"WindowsApplication17.db1.mdb" _
)
Dim Reader As New BinaryReader(s)
Dim fs As New FileStream("C:\db1.mdb", FileMode.CreateNew)
Const BlockSize As Integer = 1024 ' Read blocks of 1,024 bytes.
Dim BytesRead As Long
Dim Buffer() As Byte
Do While BytesRead < Reader.BaseStream.Length
Buffer = Reader.ReadBytes(BlockSize)
fs.Write(Buffer, 0, Buffer.Length)
Debug.Write(System.Text.Encoding.Default.GetString(Buffer))
BytesRead = BytesRead + Buffer.Length
Loop
Reader.Close()
fs.Close()
///
 
Back
Top