CSV Reports
CsvFileToObjectList<T> Method
Example 



KellermanSoftware.CsvReports Namespace > CsvReader Class : CsvFileToObjectList<T> Method
Read a CSV file into a list of objects. Public properties are mapped by name, they are case sensitive. It will automatically map all primitive types such as int, long, string and complex types of GUID, Enum, DateTime. Properties that do not exist are ignored.
Syntax
Public Function CsvFileToObjectList(Of T As {Class, New})( _
   ByVal filePath As String _
) As List(Of T)
Dim instance As CsvReader
Dim filePath As String
Dim value As List(Of T)
 
value = instance.CsvFileToObjectList(Of T)(filePath)
public List<T> CsvFileToObjectList<T>( 
   string filePath
)
where T: class, new()
public:
List<T^>^ CsvFileToObjectListgeneric<typename T>
( 
   String^ filePath
) 
where T: ref class, gcnew()

Parameters

filePath

Type Parameters

T
Example
//Example Mapping Class
public class TestMapper
{
    public string Name { get; set; }
    public string Birthdate { get; set; }
}
 
CsvReader csvReader = new CsvReader(); //Trial Mode
//CsvReader csvReader = new CsvReader("place user name here", "place license key here"); //License Mode
 
//Create a test file
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testReader.csv");
File.WriteAllText(filePath, "Name,Birthdate\r\nJohn,5/30/2013");
 
List<TestMapper> results = csvReader.CsvFileToObjectList<TestMapper>(filePath);
Console.WriteLine(results[0].Name);
'Example Mapping Class
Public Class TestMapper
    Public Property Name() As String
    Public Property Birthdate() As String
End Class
 
Dim csvReader As New CsvReader() 'Trial Mode
'Dim csvReader As New CsvReader("place user name here", "place license key here") 'License Mode
 
'Create a test file
Dim filePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testReader.csv")
File.WriteAllText(filePath, "Name,Birthdate" & vbCrLf & "John,5/30/2013")
 
Dim results As List(Of TestMapper) = csvReader.CsvFileToObjectList(Of TestMapper)(filePath)
Console.WriteLine(results(0).Name)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CsvReader Class
CsvReader Members