How to get progress for file copy?

P

Peter Rilling

Suppose that I want to get periodic status info when coping a file, how do I
do this? For instance, if my program copies a large files, how can I be
notified of the progress so that I can display the progress to the user?
 
M

Manish Agarwal

Use CopyFileEx API call using P/Invoke.

// The delegate for the callback.
public delegate int CopyProgressRoutineCallback(
long TotalFileSize,
long TotalBytesTransferred,
long StreamSize,
long StreamBytesTransferred,
[MarshalAs(UnmanagedType.U4)] dwStreamNumber,
[MarshalAs(UnmanagedType.U4)] dwCallbackReason,
IntPtr hSourceFile,
IntPtr hDestinationFile,
IntPtr lpData);

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool CopyFileEx(
string lpExistingFileName,
string lpNewFileName,
CopyProgressRoutineCallback lpProgressRoutine,
IntPtr lpData
ref bool pbCancel,
[MarshalAs(UnmanagedType.U4)] dwCopyFlags);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top