I have an embedded resource named "Test.exe". I want to do the following:
- Read the contents of Test.exe into a byte array.
- Write the contents of Test.exe (now in a byte array) to a new location (C:\Test.exe).
I am using the following code (found on this site) - but the problem is that "s" always returns a null value. I am using the below code as follows: byte[] b = ReadResource("Test.exe");
public static byte[] ReadResource(string resourceName)
{
using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
byte[] buffer = new byte[1024];
using (MemoryStream ms = new MemoryStream())
{
while (true)
{
int read = s.Read(buffer, 0, buffer.Length);
if (read <= 0)
return ms.ToArray();
ms.Write(buffer, 0, read);
}
}
}
}
Hopefully someone can find what I am having trouble seeing.