How do I know if a file is locked or not? I have improved this code and would like to know if you are correct or better. Another question is if it is corrupted, is the verification below valid?
public bool IsFileLocked(FileInfo file)
{
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException)
{
return true;
}
finally
{
if (stream != null)
stream.Close();
}
return false;
}