Thursday, March 21, 2019

C# - Read file and save bytes into Text file


Read file and save bytes into Text file

System.IO.FileStream stream = System.IO.File.OpenRead(@"FileFullPathRead.pdf");
byte[] fileBytes = new byte[stream.Length];
stream.Read(fileBytes, 0, fileBytes.Length);
stream.Close();

string base64 = Convert.ToBase64String(fileBytes);
System.IO.File.WriteAllText(@"FileFullPathToSave.txt", base64);