Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a Stream to file?

I have an embedded DLL in my app and I need to write it to the filesystem at runtime. I have this so far:

Dim _assembly As Assembly = Assembly.GetExecutingAssembly()
Dim _rawstream As Stream = _assembly.GetManifestResourceStream("MyFile.dll")

I just need to write _rawstream to a file now.

EDIT: This has to be .NET Framework 2 and CopyTo does not exist :(

like image 425
Jimmy D Avatar asked Oct 28 '11 12:10

Jimmy D


2 Answers

My.Computer.FileSystem.WriteAllBytes(output file, My.Resources.resourcename, False)
like image 176
Jimmy D Avatar answered Sep 18 '22 19:09

Jimmy D


Use a FileStream and write to it.

Dim fs As new FileStream("path to new file.dll", FileMode.Create)

_rawstream.CopyTo(fs)

Edit:

For pre 4.0 see this.

like image 45
Oded Avatar answered Sep 17 '22 19:09

Oded