public static bool Copy(string sourceFileName, string destFileName, bool overwrite)
{
using (TransactionScope scope = new TransactionScope())
using (KtmTransactionHandle ktmTx = KtmTransactionHandle.CreateKtmTransactionHandle())
{
NativeMethods.CopyFileFlags copyFlags = NativeMethods.CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS;
if (overwrite)
{
copyFlags = 0; // TODO - Correctness - Which flag value is this really supposed to be? Works though...
}
bool pbCancel = false;
bool status = NativeMethods.CopyFileTransacted(
sourceFileName,
destFileName,
IntPtr.Zero,
IntPtr.Zero,
ref pbCancel,
copyFlags,
ktmTx);
if (!status)
{
NativeMethods.HandleCOMError(Marshal.GetLastWin32Error());
}
scope.Complete();
return(status);
}
}