'Move with Replace' C# method
As a workaround to that limitation, I wrote a simple, yet useful wrapper method below that allows for overwriting the destination file.
public static void MoveWithReplace(string sourceFileName, string destFileName)
{
//first, delete target file if exists, as File.Move() does not support overwrite
if (File.Exists(destFileName))
{
File.Delete(destFileName);
}
File.Move(sourceFileName, destFileName);
}
(1 vote)
- Login or register to post comments
- 1529 reads
- Email this Quick Tip
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)







Comments
Tobias Hertkorn replied on Fri, 2008/02/29 - 5:48pm