Пример #1
0
        public static void CopyFile(
            string sourceFilePath,
            string destinationFilePath,
            bool overwriteExisting)
        {
            sourceFilePath      = CheckAddLongPathPrefix(sourceFilePath);
            destinationFilePath = CheckAddLongPathPrefix(destinationFilePath);

            if (!PInvokeHelper.CopyFile(sourceFilePath, destinationFilePath, !overwriteExisting))
            {
                // http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx.

                var lastWin32Error = Marshal.GetLastWin32Error();
                throw new Win32Exception(
                          lastWin32Error,
                          string.Format(
                              Resources.ErrorCopyingFile,
                              lastWin32Error,
                              sourceFilePath,
                              destinationFilePath,
                              CheckAddDotEnd(new Win32Exception(lastWin32Error).Message)));
            }
        }