Example #1
0
        /// <summary>
        /// CopyFile2 wrapper. Only available on Windows8 and above.
        /// </summary>
        public static void CopyFile2(string source, string destination, bool overwrite = false)
        {
            unsafe
            {
                int cancel = 0;
                COPYFILE2_EXTENDED_PARAMETERS parameters = new COPYFILE2_EXTENDED_PARAMETERS();
                parameters.dwSize      = (uint)Marshal.SizeOf <COPYFILE2_EXTENDED_PARAMETERS>();
                parameters.pfCanel     = &cancel;
                parameters.dwCopyFlags = overwrite ? 0 : CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS;

                HRESULT hr = Direct.CopyFile2(source, destination, &parameters);
                if (ErrorMacros.FAILED(hr))
                {
                    throw ErrorHelper.GetIoExceptionForHResult(hr, source);
                }
            }
        }