There are two problems with your code. The first one, you have identified:
Using goto is not generally an acceptable option. The second problem is
that you do not have any means of breaking your loop. If there is a problem
saving the file, the loop will continue forever.
To fix your code, I suggest that you put your save functionality in another
method and use a while loop to call the method something like this:
bool done = false;
while (!done)
{
done = SaveFile(e.FullPath, txtProcessedFile.Text + e.Name);
}
private bool SaveFile (string source, string destination)
{
try
{
File.Move(e.FullPath,txtProcessedFile.Text+e.Name) ;
// Insert code to verify that the new file actually exists here and
if it does:
return true;
}
catch
{
// Insert code here that can break the while loop - in other words,
return true if the user
// doesn't want to try saving again. Otherwise:
return false;
}
}
HTH
Dale Preston
MCAD, MCDBA, MCSE
"edi" <ed******@abv.bg> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
Hi,
I'm trying to move a file using File.Move(path1,path2). But the file
does not close immediately I call the method (I use Word library to
manage word file).
I can do something like this:
tryagain:
try
{
File.Move(e.FullPath,txtProcessedFile.Text+e.Name) ;
}
catch
{
goto tryagain;
}
Is there any alternative of this (I don't want to use "goto")?
Thanks.