C# System.IO.File.Move () with "Access denied" error

  • Thread starter Thread starter Jason Jacob
  • Start date Start date
J

Jason Jacob

To all,

I've tried to use System.IO.File.Move (srcFile, desFile);
but there is an exception similar to this :
The process can't access desFile because it's being used by another
process

I think that it's strange since I've already closed the FileStreams
associated to all available files already....

Any clues ??

From Jason (Kusanagihk)
 
This is a standart situation, the error message gives you whole information
of that.
The process can't access desFile because it's being used by another
process

There is just some process which is using the file someway. I am not ready
now to say what a process is it and why it holds the file but to be sure
there is one. May be you should remember the clr memory managment and check
out where that file has been accessed in your code. So to drop the object's
reference does not cause its destruction because of clr memory managment and
all resources being using by the object are held. Remeber of IDisposable
interface and its Dispose() method, may be this would be the answer.
 
Download Process Explorer from

http://www.sysinternals.com

You can use that to find out which process is locking a file. You may find its not your running application but Devenv.exe or something like that.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

To all,

I've tried to use System.IO.File.Move (srcFile, desFile);
but there is an exception similar to this :
The process can't access desFile because it's being used by another
process

I think that it's strange since I've already closed the FileStreams
associated to all available files already....

Any clues ??

From Jason (Kusanagihk)
 
I've encountered these errors when
- the file already exists in the destination directory (FileCopy
allows an overwrite, but FileMove doesn't)
- different security settings exist on the file to be moved (file
belonging to admin only...)

Regards,

Chris
 
Back
Top