title: VB.Net File.Exists() Returns True but Excel cannot Open
body: <p>I check for the existence of the file with <code>File.Exists(filePath)</code>. Then I try to open the file from within Excel with <code>Excel.Workbooks.OpenText(filePath)</code>. But Excel complains that the file's not there. What the heck?</p>
  
  <p>The context is that I am shelling out to another application to process a given file and produce a .out file, which I then convert to an Excel workbook.</p>
  
  <pre><code>'' At this point, filePath is a .txt file.
  Dim args As String = String.Format("""{0}""", filePath)
  ...
  Dim exe As String = Config.ExtractEXE
  
  Dim i As New ProcessStartInfo(exe)
  i.Arguments = args
  
  Dim p As Process = Process.Start(i)
  p.WaitForExit()
  ...
  '' filePath now becomes the .out file.
  '' Then eventually, I get around to checking:
  'If Not File.Exists(filePath) Then
  '   MsgBox("Please ensure...")
  '   Exit Sub
  'End If
  '' In response to an answer, I no longer check for the existence of the file, but
  '' instead try to open the file.
  
  Private Function fileIsReady(filePath As String) As Boolean
    Try
      Using fs As FileStream = File.OpenRead(filePath)
        Return True
      End Using
    Catch
      Return False
    End Try
  End Function
  
  Do Until fileIsReady(filePath)
    '' Wait.
  Loop
  
  ExcelFile.Convert(filePath...)
  '' Wherein I make the call to:
  Excel.Workbooks.OpenText(filePath...)
  '' Which fails because filePath can't be found.
  </code></pre>
  
  <p>Is there a latency issue, such that .Net recognizes the existence of the file before it's accessible to other applications? I just don't understand why <code>File.Exists()</code> can tell me the file is there and then Excel can't find it.</p>
  
  <p>As far as I know, the only application that might have the file open is the application I call to do the processing. But that application should be finished with the file by the time <code>p.WaitForExit()</code> finishes, right?</p>
  
  <p>I've had to deploy the application with this as a known bug, which really sucks. There's an easy workaround for the user; but still--this bug should not be. Hope you can help.</p>