It is actually useful for me to store some files in EXE to copy to selected location. I\'m generating HTML and JS files and need to copy some CSS, JS and GIFs.
Snipp
Add the files you want to your solution and then set their Build Action
property to Embedded Resource
. This will embed the file into your exe. (msdn)
Then you just need to write the code to write the file out to disk when the exe is executed.
Something like:
File.Copy("resource.bmp", @"C:\MyFile.bin");
Replace resource.bmp
with your file name.
Addendum:
If you keep the file in a sub-folder in your solution you need to make the sub-folder part of the path to resource.bmp
. Eg:
File.Copy(@"NewFolder1\resource.bmp", @"C:\MyFile.bin");
Also, you may need to set the Copy To Output Directory
property to Copy Always
or Copy If Newer
.