CSV Reports
ClassListToCsvFile<T>(IEnumerable<T>,String) Method
Example 



KellermanSoftware.CsvReports Namespace > CsvWriter Class > ClassListToCsvFile Method : ClassListToCsvFile<T>(IEnumerable<T>,String) Method
The type for the class
A list of objects
The fully qualified path
Create a CSV file from a list of objects. It will output all public properties of the class as columns.
Syntax
Public Overloads Sub ClassListToCsvFile(Of T As Class)( _
   ByVal list As IEnumerable(Of T), _
   ByVal filePath As String _
) 
Dim instance As CsvWriter
Dim list As IEnumerable(Of T)
Dim filePath As String
 
instance.ClassListToCsvFile(Of T)(list, filePath)
public void ClassListToCsvFile<T>( 
   IEnumerable<T> list,
   string filePath
)
where T: class
public:
void ClassListToCsvFilegeneric<typename T>
( 
   IEnumerable<T^>^ list,
   String^ filePath
) 
where T: ref class

Parameters

list
A list of objects
filePath
The fully qualified path

Type Parameters

T
The type for the class
Example
//Example Class
public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime BirthDate { get; set; }
}
 
CsvWriter csvWriter = new CsvWriter(); //Trial Mode
//CsvWriter csvWriter = new CsvWriter("place user name here", "place license key here"); //License Mode
 
List<Person> persons = new List<Person>();
Person person1 = new Person();
person1.FirstName = "John";
person1.LastName = "Smith";
person1.BirthDate = DateTime.Now.AddDays(-1);
persons.Add(person1);
 
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testWriter.csv");
 
csvWriter.ClassListToCsvFile(persons,filePath);
 
Console.WriteLine(File.ReadAllText(filePath));
'Example Class
Public Class Person
    Public Property FirstName() As String
    Public Property LastName() As String
    Public Property BirthDate() As Date
End Class
 
Dim csvWriter As New CsvWriter() 'Trial Mode
'Dim csvWriter As New CsvWriter("place user name here", "place license key here") 'License Mode
 
Dim persons As New List(Of Person)()
Dim Person person1 = New Person()
person1.FirstName = "John"
person1.LastName = "Smith"
person1.BirthDate = Date.Now.AddDays(-1)
persons.Add(person1)
 
Dim filePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testWriter.csv")
 
csvWriter.ClassListToCsvFile(persons,filePath)
 
Console.WriteLine(File.ReadAllText(filePath))
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

CsvWriter Class
CsvWriter Members
Overload List