I'm ultimately trying to read a file, store in a blob in a Cassandra database, then later write it back to disk. Was having issues, and simplified to the following code that demonstrates the issue. The same code works fine with .txt and .csv files, but doesn't work with an Excel spreadsheet. I'm not sure if it's an encoding issue, and how to fix it. I tried Encoding.Unicode, but that didn't work either.
static void testFileReadWrite()
{
string filenameIn = @"c:\demo\Timesheet.xls";
string filenameOut1 = @"c:\demo\Timesheet_Test1.xls";
string filenameOut2 = @"c:\demo\Timesheet_Test2.xls";
string fileContents1 = File.ReadAllText(filenameIn);
File.WriteAllText(filenameOut1, fileContents1);
string fileContents2 = File.ReadAllText(filenameIn, Encoding.Unicode);
File.WriteAllText(filenameOut2, fileContents2, Encoding.Unicode);
}
Original file size was 536,576. Test1 was 1,282,808 and Test2 was 536,578. Obviously, I want the same size file out as I read in, then I will do a file compare on it to validate it. I also want the program to work with any file type, it's just that Excel was the first one that demonstrated the issue.