CSV Reports
AppendToCsvWriter<T>(T,TextWriter,List<String>,Boolean) Method
Example 



KellermanSoftware.CsvReports Namespace > CsvWriter Class > AppendToCsvWriter Method : AppendToCsvWriter<T>(T,TextWriter,List<String>,Boolean) Method
The type of the object
The value of the object
Where to write to
The order of the properties to write out
If true, the header will be output
Append an object to a CSV writer
Syntax
Public Overloads Sub AppendToCsvWriter(Of T As Class)( _
   ByVal objectValue As T, _
   ByVal writer As TextWriter, _
   ByVal propertyNameOrder As List(Of String), _
   ByVal outputHeader As Boolean _
) 
Dim instance As CsvWriter
Dim objectValue As T
Dim writer As TextWriter
Dim propertyNameOrder As List(Of String)
Dim outputHeader As Boolean
 
instance.AppendToCsvWriter(Of T)(objectValue, writer, propertyNameOrder, outputHeader)
public void AppendToCsvWriter<T>( 
   T objectValue,
   TextWriter writer,
   List<string> propertyNameOrder,
   bool outputHeader
)
where T: class
public:
void AppendToCsvWritergeneric<typename T>
( 
   T^ objectValue,
   TextWriter^ writer,
   List<String^>^ propertyNameOrder,
   bool outputHeader
) 
where T: ref class

Parameters

objectValue
The value of the object
writer
Where to write to
propertyNameOrder
The order of the properties to write out
outputHeader
If true, the header will be output

Type Parameters

T
The type of the object
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, "appendWriter.csv");
 
using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
    using (TextWriter writer = new StreamWriter(stream))
    {
        for (int i = 0; i < persons.Count; i++)
        {
            bool outputHeader = i == 0;
            csvWriter.AppendToCsvWriter(persons[i], writer, propertyOrder, outputHeader);
        }
    }
}
 
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, "appendWriter.csv")
 
Using stream As New FileStream(filePath, FileMode.Create, FileAccess.Write)
    Using writer As TextWriter = New StreamWriter(stream)
        For i As Integer = 0 To persons.Count - 1
            Dim outputHeader As Boolean = i = 0
            csvWriter.AppendToCsvWriter(persons(i), writer, propertyOrder, outputHeader)
        Next i
    End Using
End Using
 
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