How to read .csv file extension in .net C#
- Do you wish to read the file contents, or simply the file extension???Adriaan Stander– Adriaan Stander2010-12-22 05:57:40 +00:00Commented Dec 22, 2010 at 5:57
- 2duplicates stackoverflow.com/questions/906841/csv-parser-reader-for-c & stackoverflow.com/questions/1375410/very-simple-c-csv-reader - please search before asking a question. And this question definitely doesn't deserve an upvote!Kirk Broadhurst– Kirk Broadhurst2010-12-22 06:03:51 +00:00Commented Dec 22, 2010 at 6:03
- possible duplicate of Reading CSV files in .NET?Kirk Broadhurst– Kirk Broadhurst2013-08-12 23:44:40 +00:00Commented Aug 12, 2013 at 23:44
Add a comment |
2 Answers
I just write my own - it's a one-liner!
using System.IO.File; return ReadAllLines(@"C:\V3.txt").Select(line => line.Split(',')).ToList(); This will return a list where each item is a string[], contain each of the comma separated values.
3 Comments
Jonathan Wood
That ones going to cause problems if the data contains embedded commas or double quotes.
Kirk Broadhurst
Very true. If I have to suffer with delimited files I always insist on non-comma delimited; tab or pipe delimited is much better.
Kirk Broadhurst
@ShrutiKapoor what do you mean? What's changed - which part doesn't work?
FileHelper has mostly done the trick for me and it iss easy to use and has reasonable examples at the home page: http://www.filehelpers.com/