Does anyone have an example of working with a progress bar while copying a file, or can direct me to a place where this question has been asked?
private void Transferfiles(DirectoryInfo source, DirectoryInfo target)
{
int e = 0
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
foreach (FileInfo eachhfile in source.GetFiles())
{
eachhfile.CopyTo(Path.Combine(target.ToString(), eachhfile .Name));
BytesToKilobytes += ((eachhfile .Length / 1024) / 1024);
e = BytesToKilobytes ;
backgroundWorker1.ReportProgress(e);
}
foreach (DirectoryInfo SubDirectory in source.GetDirectories())
{
DirectoryInfo newTargetDirectory =
target.CreateSubdirectory(diSourceSubDir.Name);
Transferfiles(SubDirectory, newTargetDirectory );
}
}
The above is the code I have used so far. It works but doesn't really give me what I want. I am looking for a way to make the progress bar update as the file is copying, so that the progress bar will keep moving until the file has finished copying.