title: File.Copy Access Denied
body: <p>I have a problem with copying from local disk to flash. The code worked before, but after I create anoteher foreach loop and I had to create new objects, the File.Copy functionality isn't working anymore.
  In value File | System.IO.File there are values like: Error_Access_Denied | 5, Error_Invalid Parameter| 87, GetFileExInfoStandard | 0.</p>
  
  <p>edit: locationUSB present file path on flash. (locationUSB == "D:\something.hex") and x._location == "C:\something_1.hex" .</p>
  
  <pre><code>foreach (object item in this.dataGridView2.Rows)
  {
      versionOnDisk = this.VersionInt(x._version);
      versionOnFlash = this.VersionInt(((DataGridViewRow)item).Cells[2].Value.ToString());
  
      if (versionOnFlash &gt; versionOnDisk)
          forbidCopying = true;
      else
          locationUSB = _logicalDrive + ((DataGridViewRow)item).Cells["Filename"].Value.ToString();  // &lt;-- location value (because of the foreach)
  
      if (!forbidCopying)
          File.Copy(x._location, locationUSB, true);   // &lt;--
      else if (AllowDelete.Checked)
          File.Delete(locationUSB);
  }
  </code></pre>
  
  <p>edit:
  If I change the location into logical drive path, which value is "D:\" I get the DirectoryNotFoundException was unhandled: Could not find a part of the path 'D:\'.</p>