Practical .NET · Lesson 7

Project files

A run can write files. You decide whether to keep them.

How it works

Directory.CreateDirectory makes the out folder if it is missing. Path.Combine joins folder and file names. WriteAllLines writes one line per item, and ReadAllLines reads them back. After the run, out/report.txt appears under the output as a written file. It joins the project only if you tap Add to project.

A working example

Directory.CreateDirectory("out");
var path = Path.Combine("out", "report.txt");

File.WriteAllLines(path, new[] { "paid 12.50", "paid 4.25" });

var lines = File.ReadAllLines(path);
Console.WriteLine($"{lines.Length} lines in {path}");
Console.WriteLine(lines[0]);

Expected output

2 lines in out/report.txt
paid 12.50
Try this
Write to a folder of its own so it is easy to find.