1

I have loaded a CSV file

Here is a sample of the content available in the CSV file

Name,Address,Address1,LandMark,User_location,City,State,Phone1,Phone2,Email,Category
Sriram Electricals and Plumbing Contractors,No 12, Vinayakar Koil Street Easa,"Back Side Of Therasa School,",Pallavaram,Chennai,Tamil Nadu,(044) 66590405,,sriram@gmail.com,Electrican

I've tried to convert the file to a list

public ActionResult UserCsv(HttpPostedFileBase uploadfile)
{      
    using (var sr = new StreamReader(uploadfile.InputStream, Encoding.UTF8))
    {   
         var reader = new CsvReader(sr); 
         //CSVReader will now read the whole file into an enumerable
         IEnumerable<UserCSVModel> records = reader.GetRecords<UserCSVModel>();
    }
}

Unable to get a correct output.

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40

2 Answers2

0

try this article:

http://www.codeproject.com/Articles/415732/Reading-and-Writing-CSV-Files-in-Csharp

Or this Q on stack over flow:

Reading CSV file and storing values into an array

hope it helps.

Community
  • 1
  • 1
Monir Tarabishi
  • 716
  • 1
  • 16
  • 30
0

Have a look a http://www.filehelpers.net/. It's a great library for working with CSV files and will give you an Enumerable that you can work with

Marcos Meli
  • 3,468
  • 24
  • 29
Dave
  • 583
  • 1
  • 4
  • 11