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 files to project resources and set their "Build Action" as "Embedded Resource".
Now extract any file (text or binary) using this snippet:
WriteResourceToFile("Project_Namespace.Resources.filename_as_in_resources.extension", "extractedfile.txt");
public static void WriteResourceToFile(string resourceName, string fileName)
{
int bufferSize = 4096; // set 4KB buffer
byte[] buffer = new byte[bufferSize];
using (Stream input = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
using (Stream output = new FileStream(fileName, FileMode.Create))
{
int byteCount = input.Read(buffer, 0, bufferSize);
while (byteCount > 0)
{
output.Write(buffer, 0, byteCount);
byteCount = input.Read(buffer, 0, bufferSize);
}
}
}
Don't know how deep is it correct according to this article: http://www.yoda.arachsys.com/csharp/readbinary.html but it works.