C#/.NET use Unicode.
a Unicode char is 2 bytes in size. A byte is one... byte. Converting like this will not work. Additionally, when you have certain code points in a string it will create different unicode characters. You should not be using a string. I am not on Windows atm so I cannot test with an executable but you could use something like fc on the original and destination to see how the conversions are screwing up the executable.
You are reading the entire file into memory, then writing that to a new file. Why? Why not do both at once? eg.
int bufferSize = 1024 * 64;
using(FileStream is = new FileStream("source",FileMode.Open,FileAccess.Read))
{
using (FileStream fs = new FileStream("destination", FileMode.OpenOrCreate, FileAccess.Write))
{
int bytesRead = -1;
byte[] bytes = new byte[bufferSize];
while ((bytesRead = is.Read(bytes, 0, bufferSize)) > 0)
{
fs.Write(bytes, 0, bytesRead);
}
fs.Flush();
}
}
Or, could do something really crazy like use the provided .NET framework method for this purpose:
File.Copy("Source","Destination");