Home All Groups Group Topic Archive Search About

Copying files with progress bar

Author
27 Nov 2007 6:01 PM
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

Author
27 Nov 2007 6:24 PM
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

Show quoteHide quote
"kimiraikkonen" <kimiraikkone***@gmail.com> schreef in bericht
news:5d0c620c-ffeb-4dca-a790-f56461d3a93f@o42g2000hsc.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
Author
27 Nov 2007 6:36 PM
kimiraikkonen
Show quote Hide quote
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.com> schreef in berichtnews:5d0c620c-ffeb-4dca-a790-f56461d3a***@o42g2000hsc.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.
Author
27 Nov 2007 9:49 PM
Herfried K. Wagner [MVP]
"kimiraikkonen" <kimiraikkone***@gmail.com> schrieb:
> 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/>
Author
28 Nov 2007 5:29 AM
Cor Ligthert[MVP]
Hi Herfried,

Thanks for the information, this was new for me.


Cor
Author
28 Nov 2007 10:06 AM
kimiraikkonen
On Nov 27, 11:49 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h***@gmx.at> wrote:
> "kimiraikkonen" <kimiraikkone***@gmail.com> schrieb:
>
> > 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.
Author
28 Nov 2007 10:45 AM
kimiraikkonen
On Nov 27, 11:49 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h***@gmx.at> wrote:
> "kimiraikkonen" <kimiraikkone***@gmail.com> schrieb:
>
> > 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.