I am using FileHelpers to parse CSV files uploaded on an ASP.NET app.
Two different CSV file structures (ie. different amount of columns) will be uploaded, so before I create the FileHelpers engine with the model of the structure to be parsed, I read the first line of the file like this:
string line = "";
using (StreamReader reader = new StreamReader(file.InputStream))
{
line = reader.ReadLine();
}
int fieldCount = line.Count(l => l == ',');
This works, and gives me the column count, but it breaks anything else I want to do with file.InputStream
:
var engine = new FileHelperEngine<CSVModel>();
CSVModel[] records;
records = (CSVModel[])engine.ReadStream(new StreamReader(file.InputStream),
Int32.MaxValue);
// etc etc
Why does this happen? I've tried to take away the using
and just manually close() the StreamReader but it doesn't help.