''' FIRST ATTEMPT
Dim sWriter As Stream = (Me.GetType().Assembly.GetManifestResourceStream("foo"))
Dim x As Integer
Dim fFile As New FileStream("bar.ext", FileMode.OpenOrCreate)
For x = 1 To sWriter.Length
fFile.WriteByte(sWriter.ReadByte)
Next
fFile.Close()
''' SECOND ATTEMPT
'Open the Embeded resource
Dim resourceStream As IO.Stream = Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Foo")
'Open FileStream to write out to
Dim writer As New IO.FileStream("bar.ext", IO.FileMode.Create, IO.FileAccess.Write)
'Write out all bytes of the stream
Const size As Int16 = 4096
Dim buffer(size) As Byte
Dim numBytes As Int32 = 0
Do
numBytes = resourceStream.Read(buffer, 0, size)
writer.Write(buffer, 0, numBytes)
Loop While (numBytes > 0)
'Close both streams and clean up
resourceStream.Close()
resourceStream.Dispose()
writer.Close()
writer.Dispose()
|