Hola a todos
Estoy copiando unos cuantos ficheros de C: a un Servidor.
El problema es que a Windows XP se le corta la conexión unos instante y
luego la recupera.
Si al programa le pilla el Corte cuando esta copiando da error.
Hay alguna manera de hacer que el Programa ReEstablezca la conexión, o al
menos, que se espere para copiar hasta que Windows XP reestablezca la
conexión.
Un saludo y gracias por todo
Darhas
Este es el código que utilizo para copiar, está sacado de las MSDN de
Microsoft:
private bool CopiarFichero(string DirectorioOrigen, string FicheroOrigen,
string DirectorioFinal, string FicheroFinal, bool SobreEscribir)
{
bool Correcto = false;
bool CorrectoOrigen = false;
bool CorrectoFINAL = false;
string fileName = FicheroOrigen;
string sourcePath = DirectorioOrigen;
string targetPath = DirectorioFinal;
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath,
FicheroFinal);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they
already exist.
foreach (string s in files)
{
// Use static Path methods to extract only the file name
from the path.
if (SobreEscribir == true)
{
if (!System.IO.File.Exists(destFile))
{
System.IO.File.Delete(destFile);
System.IO.File.Copy(sourceFile, destFile);
Correcto = true;
}
}
else
{
if (!System.IO.File.Exists(destFile))
{
System.IO.File.Copy(sourceFile, destFile, true);
Correcto = true;
}
else
{
Correcto = false;
}
}
}
}
else
{
Console.WriteLine("Source path does not exist!");
Correcto = false;
}
// Keep console window open in debug mode.
//Console.WriteLine("Press any key to exit.");
//Console.ReadKey();
return (Correcto);
}
Leer las respuestas