Saludos!
Estimados, tengo una pregunta, como puedo verificar que un archivo no esta
bloqueado o tomado por otro proceso mediante codigo?
cualquier ayuda sera bienvenida, he tratado de la siguiente manera:
try
{
foreach (string _file in _mail.Attachment)
{
System.IO.FileInfo lockFile = new System.IO.FileInfo(_file);
bool tmpBool2;
bool tmpBool3;
if (System.IO.File.Exists(lockFile.FullName))
{
tmpBool2 = true;
_log.Warning(tmpBool2.ToString(), "One");
}
else
{
tmpBool2 =
System.IO.Directory.Exists(lockFile.FullName);
}
if (System.IO.File.Exists(lockFile.FullName))
{
System.IO.File.Delete(lockFile.FullName);
tmpBool3 = true;
_log.Warning("true"," Two");
}
else if (System.IO.Directory.Exists(lockFile.FullName))
{
System.IO.Directory.Delete(lockFile.FullName);
tmpBool3 = true;
_log.Warning("true", " Three");
}
else
{
tmpBool3 = false;
_log.Warning("true", " Four");
}
if (tmpBool2 && !tmpBool3)
{
throw new System.IO.IOException("No se puede
eliminar archivo " + lockFile);
}
}
}