Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Writing to a txt file in resource folder in Visual Studio 2019

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);
        }
    } 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading