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

File.Copy problem large number files over network

P: n/a
I am using standard File.Copy(source,dest,true) method in C# and I have
problem with copying large number of files.
Here is my code:
foreach (FileInfo file in files)
{
File.Copy(file.FullName,destPath+ "\\" + file.Name, true);
}

This code copies only 5 or 10 files but in "files" collection there is 60
files.
I copy files over local network.
I think that this code (File.Copy) calls
Win32Native.CopyFile(fullPathInternal, dst, !overwrite))
and after that it runs again if foreach but coping is not finished.
After large number requests is send File.Copy is not finished for all files.
Is there a way to get response after File.Copy operation is finished?
Thanks
Radenko
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Instead of using File.Copy you could just use something like FileStream. In
that case you would have greater control over the copy process and you could
do it either in synchronous or asynchronous manner. There is a lot of
examples out there how to use FileStream. Hope that helps.

"Radenko_Zec" <Ra********@discussions.microsoft.comwrote in message
news:66**********************************@microsof t.com...
I am using standard File.Copy(source,dest,true) method in C# and I have
problem with copying large number of files.
Here is my code:
foreach (FileInfo file in files)
{
File.Copy(file.FullName,destPath+ "\\" + file.Name, true);
}

This code copies only 5 or 10 files but in "files" collection there is 60
files.
I copy files over local network.
I think that this code (File.Copy) calls
Win32Native.CopyFile(fullPathInternal, dst, !overwrite))
and after that it runs again if foreach but coping is not finished.
After large number requests is send File.Copy is not finished for all
files.
Is there a way to get response after File.Copy operation is finished?
Thanks
Radenko
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.