CSV Reports
AppendToCsvFile<T>(T,String,List<String>) Method
Example 



KellermanSoftware.CsvReports Namespace > CsvWriter Class > AppendToCsvFile Method : AppendToCsvFile<T>(T,String,List<String>) Method
The type of the class
The value to output
The path to the output file
The order to output the properties
Append to a CSV file. For the first item passed it will create the header if OutputHeader is true.
Syntax
Public Overloads Sub AppendToCsvFile(Of T As Class)( _
   ByVal objectValue As T, _
   ByVal filePath As String, _
   ByVal propertyNameOrder As List(Of String) _
) 
Dim instance As CsvWriter
Dim objectValue As T
Dim filePath As String
Dim propertyNameOrder As List(Of String)
 
instance.AppendToCsvFile(Of T)(objectValue, filePath, propertyNameOrder)
public void AppendToCsvFile<T>( 
   T objectValue,
   string filePath,
   List<string> propertyNameOrder
)
where T: class
public:
void AppendToCsvFilegeneric<typename T>
( 
   T^ objectValue,
   String^ filePath,
   List<String^>^ propertyNameOrder
) 
where T: ref class

Parameters

objectValue
The value to output
filePath
The path to the output file
propertyNameOrder
The order to output the properties

Type Parameters

T
The type of the class
Example
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.AddYears(-6);
persons.Add(person1);
 
Person person2 = new Person();
person2.FirstName = "Sara";
person2.LastName = "Smith";
person2.BirthDate = DateTime.Now.AddYears(-4);
persons.Add(person2);
 
//Order the output by Last Name, First Name, Birth Date
List<string> propertyOrder = new List<string>();
propertyOrder.Add("LastName");
propertyOrder.Add("FirstName");
propertyOrder.Add("BirthDate");
 
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testAppend.csv");
 
foreach (var person in persons)
{
    csvWriter.AppendToCsvFile(person, filePath, propertyOrder);
}
 
Console.WriteLine(File.ReadAllText(filePath));
Dim csvWriter As New CsvWriter() 'Trial Mode
'CsvWriter csvWriter = new CsvWriter("place user name here", "place license key here"); //License Mode
 
Dim persons As New List(Of Person)()
Dim person1 As New Person()
person1.FirstName = "John"
person1.LastName = "Smith"
person1.BirthDate = Date.Now.AddYears(-6)
persons.Add(person1)
 
Dim person2 As New Person()
person2.FirstName = "Sara"
person2.LastName = "Smith"
person2.BirthDate = Date.Now.AddYears(-4)
persons.Add(person2)
 
'Order the output by Last Name, First Name, Birth Date
Dim propertyOrder As New List(Of String)()
propertyOrder.Add("LastName")
propertyOrder.Add("FirstName")
propertyOrder.Add("BirthDate")
 
Dim filePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testAppend.csv")
 
For Each person In persons
    csvWriter.AppendToCsvFile(person, filePath, propertyOrder)
Next person
 
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