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.
edit: locationUSB present file path on flash. (locationUSB == “D:\something.hex”) and x._location == “C:\something_1.hex” .
foreach (object item in this.dataGridView2.Rows)
{
versionOnDisk = this.VersionInt(x._version);
versionOnFlash = this.VersionInt(((DataGridViewRow)item).Cells[2].Value.ToString());
if (versionOnFlash > versionOnDisk)
forbidCopying = true;
else
locationUSB = _logicalDrive + ((DataGridViewRow)item).Cells["Filename"].Value.ToString(); // <-- location value (because of the foreach)
if (!forbidCopying)
File.Copy(x._location, locationUSB, true); // <--
else if (AllowDelete.Checked)
File.Delete(locationUSB);
}
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:\’.
Most probably after creating new files, you are not closing the
FileStreams. Close theFileStreams of the newly created files using eithermyFile.Close();or create new files insideusing (var myFile = File.Create(myPath))blocks.