I have an issue with trying to write to a txt file within my resource folder, I am new to C# and to Visual Studio so I am fairly lost and would appreciate any help. The issue is simply that nothing is written to the txt file.
private void button1_Click(object sender, EventArgs e)
{
int b = numericUpDown1.GetHashCode();
int c = numericUpDown2.GetHashCode();
int d = numericUpDown3.GetHashCode();
try
{
StreamWriter sw = new StreamWriter("orders.txt");
sw.WriteLine("Burger(s) " b);
sw.WriteLine("Chip(s): " c);
sw.WriteLine("Drink(s) " d);
sw.Close();
}
catch (Exception ex)
{
Console.WriteLine("Exception: " ex.Message);
}
}
CodePudding user response:
You can use this method:
class WriteAllLines
{
public static async Task ExampleAsync()
{
string[] lines =
{
"First line", "Second line", "Third line"
};
await File.WriteAllLinesAsync("WriteLines.txt", lines);
}
}
from microsoft