InputFile and TextFieldParser to parse csv

184 views Asked by At

I can parse a CSV file by using the file path and TextFieldParser. Now I'm trying to parse a CSV file received from InputFile component. Here is what I tried:

var stream = e.File.OpenReadStream();
var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
stream.Close();

using (var parser = new TextFieldParser(memoryStream))
{
    parser.TextFieldType = FieldType.Delimited;
    parser.SetDelimiters(";", ",");

    while (!parser.EndOfData)
    {
        //Do something here
    }
}

But when I run that, it does not enter the using block and never go further. What should I do?

Thanks

1

There are 1 answers

0
Hassan Rasouli On

use try-catch block for see Exceptions and error details.