Code below is used to read fixed width uploaded file content text file using FileHelpers in ASP .NET MVC2
First and last line lengths are smaller and ReadStream causes e
You could use the BeforeReadRecord event to check the format of the line. Set the SkipThisRecord
property in the event data if it's the first record. Determining if it's the last record is something of a problem, but you could just check the length or format instead. Of course, that'll prevent you from catching errors caused by malformed records.
Another possibility is to load the entire file into memory using File.ReadAllLines
. Remove the first and last items from the resulting array, turn it back into a string, and then call ReadString. Or you could write the strings to a MemoryStream
and call ReadStream
.