title: How to get passed System.UnauthorizedAccessException when writing to a file in Application.StartUpPath?
body: <p>When I'm writing to a file I created in Application.StartUpPath in Visual Studios it gives me the System.UnauthorizedAccessException error. Is there a way to allow access to it? c:\Users\Jesse\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs:line 112 is the direct path that the error is producing. I already tried File.SetAttributes. This is the area producing the error:</p>
  
  <pre><code>public void writeAll()
      {
          var path = Application.StartupPath;
          try
          {
              if (!File.Exists(path))
              {
                  File.CreateText(path);
              }
  
              using (StreamWriter Writer = new StreamWriter(path))
              {                                       
                  foreach (TextBox textBox in tableLayoutPanel1.Controls.OfType&lt;TextBox&gt;())
                  {
                      Writer.WriteLine(textBox.Text);
                  }
  
                  foreach (Label label in tableLayoutPanel1.Controls.OfType&lt;Label&gt;())
                  {
                      Writer.WriteLine(label.Text);
                  }
              }
          }
          catch (Exception e)
          {
              Console.WriteLine("The process failed: {0}", e.ToString());
          }
  </code></pre>
  
  <p>Help is appreciated!</p>