Copy files and progressbar

  • Thread starter Thread starter Reidar
  • Start date Start date
R

Reidar

I want to copy a file from a server to a local machine.
The process should be shown displayed by a progressbar.
Has anybody an example of this?
reidarT
 
You may not get much of a response as both working a progress bar
control and copying a file, at least with the File.Copy method are
both so absurdly simple, no one will bother to help. And if you do use
the FileCopy method to copy the file there ain't no way in hell you can
hook a progress bar to it (if there is some way, I'd love to hear
it!!).

To hook a file copy operation to a progress bar you are going to have
to read a chunk of the file with some File Reader mechanism (there are
a couple, look up FileReader class and FileStream class), update the
progress bar, and write the chunk out to the new file. If the file is
binary, you will need to hook a BinaryReader to your input stream and a
BinaryWriter to your output stream. All this is covered pretty well by
the help text.
 
(e-mail address removed) schreef:
You may not get much of a response as both working a progress bar
control and copying a file, at least with the File.Copy method are
both so absurdly simple, no one will bother to help. And if you do use
the FileCopy method to copy the file there ain't no way in hell you can
hook a progress bar to it (if there is some way, I'd love to hear
it!!).

To hook a file copy operation to a progress bar you are going to have
to read a chunk of the file with some File Reader mechanism (there are
a couple, look up FileReader class and FileStream class), update the
progress bar, and write the chunk out to the new file. If the file is
binary, you will need to hook a BinaryReader to your input stream and a
BinaryWriter to your output stream. All this is covered pretty well by
the help text.

A time ago I found this URL, it's probably just what you need:
http://khsw.blogspot.com/2005/08/copy-file-with-progressbar-in-vbnet.html
 
That was some interesting code. I do not like calling APIs directly
from .NET code, but I suppose sometimes it's necessary. And writing a
class wrapper around them and make them look .NETish would be
acceptable.
 
Back
Top