Kernel32CopyFileEx Method

Copies an existing file to a new file, notifying the application of its progress through a callback function.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static bool CopyFileEx(
	string existingFileName,
	string newFileName,
	DelegatesCopyProgressRoutine progressRoutine,
	IntPtr data,
	ref bool refCancel,
	CopyFileFlags copyFlags
)

Parameters

existingFileName  String
The name of an existing file.
newFileName  String
The name of the new file.
progressRoutine  DelegatesCopyProgressRoutine
The address of a callback function of type LPPROGRESS_ROUTINE that is called each time another portion of the file has been copied.

This parameter can be NULL.

data  IntPtr
The argument to be passed to the callback function.
refCancel  Boolean
If this flag is set to TRUE during the copy operation, the operation is canceled.

Otherwise, the copy operation will continue to completion.

copyFlags  CopyFileFlags
Flags that specify how the file is to be copied.

Return Value

Boolean
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

To get extended error information call GetLastWin32Error.

If progressRoutine returns PROGRESS_CANCEL due to the user canceling the operation, CopyFileEx(String, String, DelegatesCopyProgressRoutine, IntPtr, Boolean, CopyFileFlags) will return zero and GetLastWin32Error will return ERROR_REQUEST_ABORTED. In this case, the partially copied destination file is deleted.

If progressRoutine returns PROGRESS_STOP due to the user stopping the operation, CopyFileEx(String, String, DelegatesCopyProgressRoutine, IntPtr, Boolean, CopyFileFlags) will return zero and GetLastWin32Error will return ERROR_REQUEST_ABORTED. In this case, the partially copied destination file is left intact.

Remarks

See Also