From 2a1cd4fda8a4a8e649910d16b4dfa1ce7ae63543 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 12 May 2023 09:24:40 +0800 Subject: *misc --- .../appending-to-an-existing-file/index.html | 476 +++++++++++++++++++++ 1 file changed, 476 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/docs/examples/writing/appending-to-an-existing-file/index.html (limited to 'ThirdParty/CsvHelper-master/docs/examples/writing/appending-to-an-existing-file/index.html') diff --git a/ThirdParty/CsvHelper-master/docs/examples/writing/appending-to-an-existing-file/index.html b/ThirdParty/CsvHelper-master/docs/examples/writing/appending-to-an-existing-file/index.html new file mode 100644 index 0000000..38dccda --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/writing/appending-to-an-existing-file/index.html @@ -0,0 +1,476 @@ + + + + + + + + + + + + + + + + + + + + + + + Appending To An Existing File | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Appending to an Existing CSV File

+
Example
+
void Main()
+{
+	var records = new List<Foo>
+	{
+		new Foo { Id = 1, Name = "one" },
+	};
+
+	// Write to a file.
+	using (var writer = new StreamWriter("path\\to\\file.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\\to\\file.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; }
+}
+
+
Output
+
Id,Name
+1,one
+2,two
+
+ +
+
+
+
+ +

+ + + + + + + + + + + -- cgit v1.1-26-g67d0