Click here to Skip to main content
15,921,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a test harness, which tests CopyFileEx from kernel32.dll for copying files across the WAN.

My code is based upon on a link found on here

What I have done is create a shared folder on my C:\ using netapi and placed inside the folder a test file. Then I created a thread to call my CopyFileEx and using the main thread in my Console Application I disconnect my share folder after 1 second. The purpose of this is test my code when COPY_FILE_RESTARTABLE is called in CopyFileEx once the share folder is reconnected and the copying continues.

The problem is when I add to the delegate (CopyProgressHandler), a streamwriter to write the bytes to a text file, it throws an exception that the file is being used by another process.

So, my question is how can record the number of bytes that have been written when CopyFileEx has been called to a text file when I have it running under its own thread?

In essence I need to record the number of bytes written when a share is removed and reintroduced. Also is it possible to record the point when copying has been interrupted?
Posted

1 solution

Well, don't use CopyFileEx. You can get all kind of control over the process if you copy the file in .NET code. You can use the classes System.IO.BinaryReader and System.IO.BinaryWriter and read data from one file and write it in other file in cycle using a buffer of some size. See:

http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.binarywriter.aspx[^].

&mash;SA
 
Share this answer
 
Comments
Member 2972992 25-Nov-11 17:26pm    
I can't use BinaryReader as the application will be copying all sort of files and we want to keep the wrapper for CopyTo in FileInfo.
Sergey Alexandrovich Kryukov 25-Nov-11 17:37pm    
I don't see why.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900