System.IO.File.Delete(BmpPath);
I have a problem with delete file.
"The process cannot access the file 'xxxx' because it is being used by another proces".
Howw can I solve my problem?
System.IO.File.Delete(BmpPath);
I have a problem with delete file.
"The process cannot access the file 'xxxx' because it is being used by another proces".
Howw can I solve my problem?
First, try to determine if the file is used by another process.
Do that using Task Manager, or a third party, like Process Explorer.
If you cannot determine using those, also try Handle.
Handle is targetted at searching for open file references, so if you do not specify any command-line parameters it will list the values of all the handles in the system that refer to open files and the names of the files. It also takes several parameters that modify this behavior.
Ultimately, in the unlikely case that none of these work, you might try rebooting your machine and see if the problem occurs again.
In that case, the culprit process is most probably started at startup, and you can continue searching with that in mind.
Your file is locked, Close your file if it is opened or in use by some other application.
If another process has the file locked, you will not be allowed to delete the file until that process has released the file.
Also check for whether file exists or not.
try using
if(System.IO.File.Exists(@"xxxxxxx\test.txt"))
{
// Use a try block to catch IOExceptions, to
// handle the case of the file already being
// opened by another process.
try
{
System.IO.File.Delete(@"xxxxxxxx\test.txt");
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
return;
}
}
Try checking whether the file is open in some program or not. If it is then close the program and then try running your code. Otherwise restart your PC and then try again.