CSV Reports
DataTableToCsvFile(DataTable,String) Method
Example 



KellermanSoftware.CsvReports Namespace > CsvWriter Class > DataTableToCsvFile Method : DataTableToCsvFile(DataTable,String) Method
The data table to read
A fully qualified file path
Create a CSV File from a data table
Syntax
Public Overloads Sub DataTableToCsvFile( _
   ByVal table As DataTable, _
   ByVal filePath As String _
) 
Dim instance As CsvWriter
Dim table As DataTable
Dim filePath As String
 
instance.DataTableToCsvFile(table, filePath)
public void DataTableToCsvFile( 
   DataTable table,
   string filePath
)
public:
void DataTableToCsvFile( 
   DataTable^ table,
   String^ filePath
) 

Parameters

table
The data table to read
filePath
A fully qualified file path
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
 
//Parameters
DataTable table = new DataTable();
table.Columns.Add("FirstName", typeof (string));
table.Columns.Add("LastName", typeof(string));
table.Columns.Add("BirthDate", typeof(string));
 
DataRow row = table.NewRow();
row["FirstName"] = "John";
row["LastName"] = "Smith";
row["BirthDate"] = DateTime.Now.AddDays(-1).ToString();
table.Rows.Add(row);
 
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testWriter.csv");
 
csvWriter.DataTableToCsvFile(table, 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
 
'Parameters
Dim table As New DataTable()
table.Columns.Add("FirstName", GetType(String))
table.Columns.Add("LastName", GetType(String))
table.Columns.Add("BirthDate", GetType(String))
 
Dim row As DataRow = table.NewRow()
row("FirstName") = "John"
row("LastName") = "Smith"
row("BirthDate") = Date.Now.AddDays(-1).ToString()
table.Rows.Add(row)
 
Dim filePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testWriter.csv")
 
csvWriter.DataTableToCsvFile(table, 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