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

FileInfo Copy() method and progressbar

P: n/a
Hi,

I used to use CopyTo() method from FileInfo class, does anyone know if there
is a way to bind this with progressbar, or with some sort of paintBox - to
show progress of moving/coping file ?

--
best regards
Stic
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Is p/invoking CopyFileEx from the kernel32 ok?
"Stefan Turalski (stic)" <st*************@kruk-inkaso.com.pl> wrote in
message news:OI*************@tk2msftngp13.phx.gbl...
Hi,

I used to use CopyTo() method from FileInfo class, does anyone know if there is a way to bind this with progressbar, or with some sort of paintBox - to
show progress of moving/coping file ?

--
best regards
Stic

Nov 15 '05 #2

P: n/a
Hi,

Yes, thats give a some sort of solution,but from simple method I have to
programm some sort of multithread application ;-/
Thats all only for this progress bar - I was wondering if progressBar could
handle events by some sort of binding with this FileInfo method, what should
be provide when we use this together a lot..

btw. If I have to use CopyFileEx from kernel32 I prefer to use some sort of
networking and do this function kernel independent.
--
best reagards,
stic (who is starting its all over again ;)

Użytkownik "Hasani" <HJ****@hotmail.c0m> napisał w wiadomości
news:Ra*********************@twister.nyc.rr.com...
Is p/invoking CopyFileEx from the kernel32 ok?
"Stefan Turalski (stic)" <st*************@kruk-inkaso.com.pl> wrote in
message news:OI*************@tk2msftngp13.phx.gbl...
Hi,

I used to use CopyTo() method from FileInfo class, does anyone know if

there
is a way to bind this with progressbar, or with some sort of paintBox - to show progress of moving/coping file ?

--
best regards
Stic

Nov 15 '05 #3

P: n/a
THe only other alternative I can think of is using Stream.Read/ Stream.Write
inside a static method and use a delegate for updating the amoutn copied.
I didn't compile it or test it but something like this is what i would do,
if you don't want to use pinvokes.
e.x.:

using System;
using System.IO;

namespace Foo
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class FileCopier
{
public delegate void AmountCopiedSoFarHandler(int value);

public static void Copy(string source, string destination,
AmountCopiedSoFarHandler callback)
{
const int bufferSize = 8192*8;
FileStream srcStream = null;
FileStream destStream = null;
try
{
srcStream = File.OpenRead(source);
destStream = File.Create(destination, bufferSize);
while(srcStream.Position < srcStream.Length)
{
byte[] data = new byte[bufferSize];
int amtRead = srcStream.Read(data, 0, bufferSize);
destStream.Write(data, 0, amtRead);
//return the amount written to so far
callback.DynamicInvoke(new object[] {destStream.Position});
}
destStream.Flush();
callback.DynamicInvoke(new object[] {destStream.Position});
}
finally
{
try
{
srcStream.Close();
}
catch{}
try
{
destStream.Flush();
}
catch{}
try
{
destStream.Close();
}
catch{}
}
}

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
}
}
}

"Stefan Turalski (stic)" <st*************@kruk-inkaso.com.pl> wrote in
message news:uc**************@tk2msftngp13.phx.gbl...
Hi,

Yes, thats give a some sort of solution,but from simple method I have to
programm some sort of multithread application ;-/
Thats all only for this progress bar - I was wondering if progressBar could handle events by some sort of binding with this FileInfo method, what should be provide when we use this together a lot..

btw. If I have to use CopyFileEx from kernel32 I prefer to use some sort of networking and do this function kernel independent.
--
best reagards,
stic (who is starting its all over again ;)

Użytkownik "Hasani" <HJ****@hotmail.c0m> napisał w wiadomości
news:Ra*********************@twister.nyc.rr.com...
Is p/invoking CopyFileEx from the kernel32 ok?
"Stefan Turalski (stic)" <st*************@kruk-inkaso.com.pl> wrote in
message news:OI*************@tk2msftngp13.phx.gbl...
Hi,

I used to use CopyTo() method from FileInfo class, does anyone know if there
is a way to bind this with progressbar, or with some sort of
paintBox - to show progress of moving/coping file ?

--
best regards
Stic


Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.