title: Create and write on .txt file using c#
body: <p>I am trying to create a .txt file using c# and write on it although my code runs without any errors the file doesn't exist after i run it </p>
  
  <pre><code>string path = @"C:\Users\stra\Documents\Visual Studio 2017\Projects\ConsoleApp2\file.txt";
  
          try
          {
              if (File.Exists(path))
              {
                  //writes to file
                  System.IO.File.WriteAllText(path,"Text to add to the file\n");
              }
              else
              {
                  // Create the file.
                  using (FileStream fs = File.Create(path))
                  {
                      System.IO.File.WriteAllText(path, "Text to add to the file\n");
                  }
  
              }
              // Open the stream and read it back.
              using (StreamReader sr = File.OpenText(path))
              {
                  string s = "";
                  while ((s = sr.ReadLine()) != null)
                  {
                      Console.WriteLine(s);
                  }
              }
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
  </code></pre>