Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate an uploaded file a csv or not with out using content type property (with out checking the extension) of file upload control in c#?

I need to check whether an upload file a csv or not with out checking the file extension. Using filecontent property also i can't find the type efficiently if a non-csv file is renamed to ".csv" extension. I need to prevent such things from happening.

Any one please suggest a method to find the content type by reading header info..

like image 486
Harun Avatar asked Nov 04 '22 22:11

Harun


1 Answers

The only way to do this is to parse the file as CSV - if it parses OK, it is CSV, if not, it isn't.

You could use a parser such as the TextFieldParser class that is part of the Microsoft.VisualBasic.Text namespace.

like image 52
Oded Avatar answered Nov 09 '22 11:11

Oded