I am writing a validation class to ensure valid files are being sent to 3rd party software. These files require a carriage return at the end but when I read them in to ensure that there is a carriage return at the end of the file the libraries I have used ignore the last line. If I put a space in this line it will read it but if I don't it gets ignored.
I've tried System.IO.File
, FileStream.ReadLines
, StreamReader
, and StringReader
using all the methods these classes have ReadAllLines()
, ReadAllText()
, ReadLines()
, etc.
Anyone know of a way around this. I haven't managed to find anything so far.
Currently, this is the line of code I have
private void readfile()
{
string[] lines = System.IO.File.ReadAllLines(filePath + file);
bool error = ErrorValidatingLastLineOfFile(lines, lines.count());
}
private bool ErrorValidatingLastLineOfFile(string[] lines, int lastLine)
{
if (lines[lastLine - 1] != "")
return true;
return false;
}
Example of file:
1. [Section1]
2. Error =
3.
4. [Section2]
5. Error =
6.
7. [Data]
8. foo,bar,
9.
numbers are lines on the file not acutally in file.