Click here to Skip to main content
16,017,376 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to create Directory and Files Coying winform application having progress bar with percentage of file size?
Posted
Comments
Sergey Alexandrovich Kryukov 6-Jun-12 13:35pm    
First of all, as UI involved, you need to tag it: WPF? Forms? Silverlight? ASP.NET? what?..

Oh, I see: Winforms. Then tag it: "Forms".
For Windows applications, the problem is pretty simple, just use System.IO. So, what's the problem? What have you done so far?
--SA
ravindrasingh1 6-Jun-12 14:07pm    
I've done this in a windows form application but still unable to control the progress bar according to the file size ,and copied files
Sergey Alexandrovich Kryukov 6-Jun-12 19:18pm    
There is no a hook into that (when a file is only partially copied), so you need to copy a file on a low level, block by block (of some size), smaller files should go by all 100% at once. I wonder why?
--SA
Sergey Alexandrovich Kryukov 7-Jun-12 0:34am    
Tag: "Forms".
--SA

1 solution

You start at the root folder of your copy job, getting the file information for every file in that folder, adding up all the file sizes, and recursively traversing the entire subfolder structure under the root, continuing to inventory all the file for size information.

Then, you go back to the root folder and start copying files, one by one, creating all the folders in the root on the target. Again, you recursively do this same thing in each and every folder in your source folder.

Keep track of the number of bytes you've copied and you can easily get the percentage complete for your progress bar.

Oh! You'll want to put the file inventory and copy code in a seperate thread so you can keep the UI thread available to handle screen updates and user clicks, like the Cancel button.
 
Share this answer
 
Comments
ravindrasingh1 6-Jun-12 14:10pm    
can you provide me the code for transfered files byte size
Dave Kreskowiak 6-Jun-12 15:04pm    
No, because you'll already have that information. You'll either know how big the file is already, or if you're doing the Read/Write of the data yourself, you will already know how much data you're read/written.

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