Discussion on:

Message 10 of 10
0 Votes
+ -
re: shafqat.net
This is because the file which has triggered the created event is likley still being copied to the target destination. Your code is trying to touch the file too quickly. I recommend putting a delay before accessing the file. I have a function which waits until the file becomes available, with a timeout of course:

private Boolean FileTransferComplete(string fullPath)
{
while (true)
{
try
{
using (StreamReader stream = new StreamReader(fullPath))
{
return true;
}
}
catch (Exception ex)
{
// If this file no longer exists then ignore it
if (ex.Message.Contains("Could not find file"))
{
return false;
}
Console.WriteLine("File is busy... Waiting for file to become available.");
Thread.Sleep(2000);
}
}
}
Posted by iBeech
20th Jul