Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Appending to an Existing CSV File with csvhelper

void Main()
{
    var records = new List<Foo>
    {
        new Foo { Id = 1, Name = "one" },
    };

    // Write to a file.
    using (var writer = new StreamWriter("path	ofile.csv"))
    using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
    {
        csv.WriteRecords(records);
    }

    records = new List<Foo>
    {
        new Foo { Id = 2, Name = "two" },
    };

    // Append to the file.
    var config = new CsvConfiguration(CultureInfo.InvariantCulture)
    {
        // Don't write the header again.
        HasHeaderRecord = false,
    };
    using (var stream = File.Open("path	ofile.csv", FileMode.Append))
    using (var writer = new StreamWriter(stream))
    using (var csv = new CsvWriter(writer, config))
    {
        csv.WriteRecords(records);
    }
}

public class Foo
{
    public int Id { get; set; }
    public string Name { get; set; }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: wpf change the content of the button wait 5 secound and then change it again 
Csharp :: Difference between PhotonNetwork.Ismasterclient and PhotonView.ismasterclient 
Csharp :: jtoken value is not exact 
Csharp :: querstring fromat asp.net c# 
Csharp :: quine in c# 
Csharp :: SonarQube UnitTests 
Csharp :: cmd.executenonquery() error in c# 
Csharp :: how to combine cells in closedXML 
Csharp :: asp net route attribute vs httpget 
Csharp :: C# change to different form 
Csharp :: asp net identity add a unique fields to user 
Csharp :: get all viewsheet revit api 
Csharp :: asp.net issue 
Csharp :: simplified if statement c# 
Csharp :: telerik mvc grid unbound column 
Csharp :: convert excel to datatable without xml configuration 
Csharp :: Enum into table C# 
Csharp :: Unity search all chidren of parent object 
Csharp :: trigger enter with nav mesh 
Csharp :: ascx access parent master page 
Csharp :: binary addition c# 
Csharp :: c# compare 2 binary files 
Csharp :: how to make your player movr the way you are rotated in unity 
Csharp :: .net 6 foreach only if not null 
Csharp :: Propertychanged is not firing up when text is change 
Csharp :: binary search tree c# stackoverflow 
Csharp :: System.InvalidOperationException: No owin.Environment item was found in the context. 
Csharp :: .net core best package for scheduler 
Csharp :: C# program applies bonus points 
Csharp :: unity variable in editor limit value 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =