C# Check if the file is ready for reading

This code checks if the file is ready for reading and that writing process is not having a lock on the file anymore.
private bool ReadyForReading(FileInfo file)
{
  try
  {
    using(new FileStream(file.FullName,FileMode.Open,FileAccess.Read,FileShare.None)){}                
    return true;
  }catch(Exception ex)
  {
    log.Warn(string.Format("Could not read file '{0}', probably writing in progress", file.Name),ex);
  return false;
  }
}

Comments

Popular posts from this blog

Tibco Rendezvous (tibrv) C# .Net example

Parse XML to dynamic object in C#