读取CSV文件的内容

时间:2014-04-05 06:08:44

标签: c# csv

我已加载CSV文件

以下是CSV文件中可用内容的示例

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

我已尝试将文件转换为列表

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>();
    }
}

无法获得正确的输出。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

看看http://www.filehelpers.net/。它是一个很棒的库,用于处理CSV文件,并为您提供可以使用的Enumerable