title: Access to the path is denied when save with filedialog
body: <p>I have two forms of saving to a file:</p>
  
  <p>One. I keep the path in the code.</p>
  
  <p>Two. I get the path from the user.</p>
  
  <p>When I save the path in the code, save successful. When I get from the user (the same path that I kept in the code) this fall with the following error:</p>
  
  <pre><code>Access to the path is denied
  </code></pre>
  
  <p>Here my save function (both ways come to the same function):</p>
  
  <pre><code>public void SaveFile(string path)
  {
      try
      {
          XmlSerializer serializer = new XmlSerializer(typeof(List&lt;MyClass&gt;));
          TextWriter textWriter = new StreamWriter(path);
          serializer.Serialize(textWriter, MyList);
          textWriter.Close();
      }
      catch (Exception e)
      {
      }
  }
  </code></pre>
  
  <p>From the user I send to this function as follows:</p>
  
  <pre><code>public void UserSave()
  {
      //Open dialog in the path that i have in the code:
      fileDialog.InitialDirectory = MyPath;
      if (fileDialog.ShowDialog() == DialogResult.OK)
      {
          SaveFile(Path.GetDirectoryName(fileDialog.FileName));
      }
  }
  </code></pre>
  
  <p>What could be the problem?</p>