FileInfo CopyTo Method Fails through mapped drive
Posted on 2006-06-16
I am trying to use the fileinfo copyto method to copy a file from a mapped drive to the local machine, when i run it, it breaks with a file not found exception, if i just hit continue after it breaks it then works fine. It seems that it is not waiting long enough to find the mapped drive?
FileInfo fi1 = new FileInfo( "J:\\BackUp-" + time.ToLongDateString().Remove( 0, time.ToLongDateString().IndexOf( " ", 0, 20 ) ).Trim().Replace( ",", "" ) + ".BAK" );
FileInfo fi2 = new FileInfo( saveBackupDialog.FileName );
fi1.CopyTo( fi2.Name, true );
I have tried inserting a pause like: System.Threading.Thread.Sleep( 5000 ); between the creation of the file and copying the file but that does not work. (The file is created just before it is copied)