Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File.Replace : Unable to remove the file being replaced

Status
Not open for further replies.

RobHudson

Programmer
Apr 30, 2001
172
GB
Hi

I am using File.Replace and am getting "Unable to remove the file being replaced".

It works fine if the replace occurs on the same drive but errors if not. For example:

Works:
File.Replace("C:\\Test\\Test.txt", "C:\\Test\\Test.txt", "C:\\Test\\Test_BAK.txt");

Fails:
File.Replace("C:\\Test\\Test.txt", "G:\\Test\\Test.txt", "C:\\Test\\Test_BAK.txt");

In both cases folders and files exist where appropriate, permissions are valid and there are no locks on the files.

Anybody got any ideas?

Cheers :)
 
From MSDN, in the File.Replace page, it says:
If the sourceFileName and destinationFileName are on different volumes, this method will raise an exception.

There's nothing more added on that. I believe (for some reason) it's just not possible over different volumes.

|| ABC
 
Thanks ABC. I did look in MSDN but must have missed it :(

Sorry for the hassle ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top