Reputation: 1302
I'm trying to move (File.Move) locked .dll file to perform application update. File.Move method was executed without exceptions. But file was not moved. I mean after executing File.Move method I have two copies of the same file: in destination folder and in source folder. Here is the code :)
File.Move(fileName, newFileName);
Could someone explain the reason of this?
Upvotes: 1
Views: 3821
Reputation: 15618
File.Move across volumes performs two operations in sequence:
It seems as though the first succeeds and the second silently fails. Results as expected.
Note from here: http://msdn.microsoft.com/en-us/library/system.io.file.move.aspx
If you try to move a file across disk volumes and that file is in use, the file is copied to the destination but not deleted from the source.
Upvotes: 7
Reputation: 472
File.Move
method will first copy the file fileName
to the file 'newFileName
'. Once the first step is successful it will delete the file 'fileName
'.
Now if the file 'fileName
' is already open/locked it will not be able to delete the file.
Upvotes: 0
Reputation: 17858
Normally in this case, you either have a separate update process that doesnt require any of the apps DLLs so you spawn the updater, which can move everything it likes, does the update, and restart the app.
Or, like an installer, you submit the change of file to occurr on next reboot.
Upvotes: 0