A small snippet being better than a long description:
var dir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(dir);
// works
using (var x = File.Open(Path.Combine(dir, "sysio.txt"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete))
System.IO.File.Move(Path.Combine(dir, "sysio.txt"), Path.Combine(dir, "sysio-moved.txt"));
// throws, but the move is successfuly performed (The process cannot access the file because it is being used by another process)
using (var x = File.Open(Path.Combine(dir, "alphafs.txt"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete))
Alphaleonis.Win32.Filesystem.File.Move(Path.Combine(dir, "alphafs.txt"),Path.Combine(dir, "alphafs-moved.txt"));
File.Move is supposed to be successful when the file has been open with FileShare.Delete flag.
In this case, File.Move sucessfully moves the file, but throws an exception (wtf ?).
NB: This issue is specific to File.Move, FileShare.Delete works perfectly fine with File.Delete()
A small snippet being better than a long description:
File.Move is supposed to be successful when the file has been open with FileShare.Delete flag. In this case, File.Move sucessfully moves the file, but throws an exception (wtf ?).
NB: This issue is specific to File.Move, FileShare.Delete works perfectly fine with File.Delete()