title: Access to the path 'C:\Users\mehdi\Desktop\sample\Test' is denied
body: <p>I'm trying to load a folder into a winForm app. App should read the files in the folder and perform some operation on the files. Following is the implementation:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
      {
          FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
          DialogResult result = folderBrowserDialog.ShowDialog();
  
          var files = from file in Directory.EnumerateFiles(folderBrowserDialog.SelectedPath, "*.chunk*", SearchOption.AllDirectories)
                      from line in File.ReadLines(file)
                      select new
                      {
                          File = file,
                          Line = line
                      };
          string newPath = folderBrowserDialog.SelectedPath;
          if (!Directory.Exists(newPath))
          {
              System.IO.Directory.CreateDirectory(newPath + @"\Test");
          }
  
          foreach (var f in files)
          {
  
              string path = f.File.ToString();
              string filename = Path.GetFileName(path);
              string s = string.Empty;
              using (StreamReader reader = new StreamReader(path, true))
              {
                  s = reader.ReadToEnd();
                  reader.Close();
              }
  
              string[] parts = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  
              using (File.CreateText(Path.Combine(newPath + @"\Test", filename+".txt")))
              { }
              using (StreamWriter sw = File.CreateText(Path.Combine(newPath + @"\Test", filename + ".txt")))
              {
                  string output = string.Empty;
                  foreach (string st in parts)
                  {
                      output += st + ",";
                  }
                  sw.Write(output);
              }
          }
      }
  </code></pre>
  
  <p>There is an error on line <code>using (File.CreateText(newPath))</code> saying: </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll</p>
    
    <p>Additional information: Access to the path 'C:\Users\mehdi\Desktop\sample\Test' is denied.</p>
  </blockquote>
  
  <p>What I'm trying to do is, App should load the folder and read each text file and perform the given task (replace out-of-sequence white space between the words with comma) and then save each file in the new folder created as <code>System.IO.Directory.CreateDirectory(newPath);</code>. All is happening as expected but when operation reaches to writing files to newly created folder <code>Test</code>, it is not allowing it the access. </p>
  
  <p>Any ideas where I'm going wrong? </p>