title: File.OpenWrite gives error while FileStream(sFile, FileMode.Open, FileAccess.ReadWrite) does not
body: <p>I have the following code to detect if a file is already in use or not:</p>
  
  <pre><code>public static bool FileInUse(string sFile)
  {
      FileStream file = null;
  
      try
      {
          file = new FileStream(sFile, FileMode.Open, FileAccess.ReadWrite);
          file.Close();
  
          file = File.OpenWrite(sFile);
          file.Close();
  
          return false;
      }
      catch (Exception)
      {
          try { file.Close(); }
          catch (Exception) { }
  
          return true;
      }
  }
  </code></pre>
  
  <p>When the file is in use then, <code>new FileStream(sFile, FileMode.Open, FileAccess.ReadWrite)</code> does not throw error but <code>File.OpenWrite(sFile)</code> throws error:</p>
  
  <blockquote>
    <p>The process cannot access the file because it is being used by another
    process.</p>
  </blockquote>
  
  <p>Why is that? Because I want to check if a file can be opened in write mode.</p>