Copying files with progress bar

K

kimiraikkonen

Hi,
I use system.io.file class to copy files but i have a difficulty about
implementing a basic / XP-like progress bar indicator during copying
process.


My code is this with no progress bar, or i couldn't find sth which
give totalbytes/written bytes class. And does system.io.file class
provide awaring of the chunks / bytes of the files bytes which are
written?

Imports System.IO
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
If opendlg.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = opendlg.FileName
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
If savedlg.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox2.Text = savedlg.FileName
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click
File.Copy(TextBox1.Text, TextBox2.Text)
End Sub
End Class
 
C

Cor Ligthert[MVP]

Kimi,

What you are doing is let the OS copy the two files for you. There is in no
way something that is usable for a progressbar for it.

Using a progressbar would even very much slow down the process. That is why
you see often in this kind of operations an avi or gif rolling in a
picturebox. I did not check it, however probably is this avi in the SDK of
your visual studio.

Cor
 
K

kimiraikkonen

Kimi,

What you are doing is let the OS copy the two files for you. There is in no
way something that is usable for a progressbar for it.

Using a progressbar would even very much slow down the process. That is why
you see often in this kind of operations an avi or gif rolling in a
picturebox. I did not check it, however probably is this avi in the SDK of
your visual studio.

Cor

Hi Cor,
Thanks for reply, you're right but i want user to be aware of the
thing that how much time or bars the copying process will take. It's
not useful or needed for small files, but while copying large files
such as hundres of MBs, it would be useful.

But still i don't hava a complete info about progress bar with that
kind of IO operations. I read somewhere System.io.file class doesn't
provide how much bytes are written, maybe an API call may be needed
which is another big issue for me.

Thanks.
 
H

Herfried K. Wagner [MVP]

kimiraikkonen said:
I use system.io.file class to copy files but i have a difficulty about
implementing a basic / XP-like progress bar indicator during copying
process.

If you are using 'My.Computer.FileSystem.CopyFile' you can set an option in
the parameters to show the progress dialog while the file is being copied.
 
K

kimiraikkonen

If you are using 'My.Computer.FileSystem.CopyFile' you can set an option in
the parameters to show the progress dialog while the file is being copied.

Hi Herfried,
Thanks for the tip, could you define a simple code for
my.filesystem.copyfile within "progressbar". It would be very helpful.
 
K

kimiraikkonen

If you are using 'My.Computer.FileSystem.CopyFile' you can set an option in
the parameters to show the progress dialog while the file is being copied.

Hi Herfried,
Thanks for the help.
I've done it with setting this parameter which calls Windows's
standard progress bar API (.net 2.0).

My.Computer.FileSystem.CopyFile(TextBox1.Text, TextBox2.Text,
FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)

Thanks.
 

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