By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,691 Members | 1,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,691 IT Pros & Developers. It's quick & easy.

Copying files with progress bar

P: n/a
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
Nov 27 '07 #1
Share this Question
Share on Google+
6 Replies

P: n/a
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

"kimiraikkonen" <ki*************@gmail.comschreef in bericht
news:5d**********************************@o42g2000 hsc.googlegroups.com...
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
Nov 27 '07 #2

P: n/a
On Nov 27, 8:24 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
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

"kimiraikkonen" <kimiraikkone...@gmail.comschreef in berichtnews:5d**********************************@o 42g2000hsc.googlegroups.com...
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
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.
Nov 27 '07 #3

P: n/a
"kimiraikkonen" <ki*************@gmail.comschrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 27 '07 #4

P: n/a
Hi Herfried,

Thanks for the information, this was new for me.
Cor
Nov 28 '07 #5

P: n/a
On Nov 27, 11:49 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comschrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Hi Herfried,
Thanks for the tip, could you define a simple code for
my.filesystem.copyfile within "progressbar". It would be very helpful.
Nov 28 '07 #6

P: n/a
On Nov 27, 11:49 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comschrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
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.
Nov 28 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.