title: Access denied error when trying to save file to directory
body: <p>I am trying to write a file on button click event but getting an unauthorized error when trying to do so.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
      {
          {
              string path = @"c:\program files\MyTest.txt";
              if (!File.Exists(path))
              {
                  // Create a file to write to.
                  using (StreamWriter sw = File.CreateText(path))
                  {
                      sw.WriteLine("Hello");
                  }
              }
  
              // Open the file to read from.
              using (StreamReader sr = File.OpenText(path))
              {
                  string s = "";
                  while ((s = sr.ReadLine()) != null)
                  {
                      Console.WriteLine(s);
                  }
              }
          }
  </code></pre>
  
  <p>Getting the error by:</p>
  
  <pre><code>using (StreamWriter sw = File.CreateText(path))
  </code></pre>
  
  <p>Not sure what i am doing wrong?  Could someone please help?</p>
  
  <p>Thanks</p>