Microsoft.KtmIntegration.NativeMethods.CopyFileTransacted C# (CSharp) Méthode

CopyFileTransacted() private méthode

private CopyFileTransacted ( [ lpExistingFileName, [ lpNewFileName, [ lpProgressRoutine, [ lpData, [ pbCancel, [ dwCopyFlags, [ hTransaction ) : bool
lpExistingFileName [
lpNewFileName [
lpProgressRoutine [
lpData [
pbCancel [
dwCopyFlags [
hTransaction [
Résultat bool
        internal static extern bool CopyFileTransacted(
            [In] string lpExistingFileName,
            [In] string lpNewFileName,
            [In] IntPtr lpProgressRoutine,
            [In] IntPtr lpData,
            [In] [MarshalAs(UnmanagedType.Bool)] ref bool pbCancel,
            [In] CopyFileFlags dwCopyFlags,
            [In] KtmTransactionHandle hTransaction);

Usage Example

        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);
                }
        }