title: Why can't I write to the .txt file?
body: <p>I want to write in a txt file, but I get</p>
  
  <blockquote>
    <p>access to the path is denied</p>
  </blockquote>
  
  <p>every time. I have tried many suggestions from google searches. None of them work: like start as admin, give full access to different users, etc.</p>
  
  <p>The test.txt is in the root folder of the project ex: "MyProject/test.txt"..</p>
  
  <p>This is the code:</p>
  
  <pre><code>private void LikeIt()
  {
      Task.Run(() =&gt;
      {       
          using (System.IO.StreamWriter file =
          new System.IO.StreamWriter(File.OpenWrite("test.txt")))
          {
              foreach (var line in ReadFile())
              {
                  // If the line doesn't contain the same ID, write the line to the file. 
                  if (!line.Contains(App.Moviess.Filmerna[index].id.ToString()))
                  {
                      file.WriteLine(App.Moviess.Filmerna[index].id.ToString() + "\r\n");
                  }
              }
          }
      });
  }
  
  private List&lt;string&gt; ReadFile()
  {
      List&lt;string&gt; lines = System.IO.File.ReadAllLines(@"C:\Users\Tomas\Desktop\MovieStarz\MovieStarz\WriteText.txt").ToList();
      return lines;
  }
  </code></pre>