I am writing an application that sends a file in text format from a machine to another i've used this code but apparently the reconstructed file is corrupted due to Encoding i think.
//file to String
byte[] bytes = System.IO.File.ReadAllBytes(filename);
string text = System.Text.Encoding.UTF8.GetString(bytes);
//String to file
byte[] byteArray = Encoding.UTF8.GetBytes(text);
FileStream ar = new FileStream("c:\\"+filename,System.IO.FileMode.Create);
ar.Write(byteArray, 0, byteArray.Length);
ar.Close();
Is there any way to convert a file to string and back to file?
Note: i want to convert all file types not only text files.