title: FileIOException, file.length threw an exception
body: <p>I am creating a tempfile using C#. </p>
  
  <pre><code>public partial class frmResults : Form
  {
      public static string caseFile = "";
  
      private void frmResults_Load(object sender, EventArgs e)
      {
          caseFile = CreateTempFiles();
          FileInfo file = new FileInfo(caseFile + ".rpt");
  
          if (file.Exists)
          {
              try
              {   
                  if (fil.Length &lt; 64000000)
                  {
                      richTabular.LoadFile(caseFile + ".rpt", RichTextBoxStreamType.PlainText);
                  } 
              }
              catch (IOException io)
              {
                  MessageBox.Show(io.GetType().Name);
              }
              catch (Exception ex)
              {
                  throw ex;
              }
          }
  
          public static string CreateTempFiles()
          {
              string sPath;
              caseFile = Path.GetTempFileName();
  
              sPath = Path.GetTempPath();
              string workDir = sPath + "\\work\\";
              // create work directory
              if (!Directory.Exists(workDir))
              {
                  Directory.CreateDirectory(workDir);
              }
              // create temp file name
              int i = 0;
              string tmpfileprefix = workDir + "Rdp";
              string tmpfilename = "";
              do
              {
                  i++;
                  tmpfilename = tmpfileprefix + i.ToString("D6");
              } while (File.Exists(tmpfilename + ".rpt"));
  
              caseFile = tmpfilename;
              return caseFile;
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p><code>Error:fil.Length = 'fil.Length'</code> threw an exception of type  <code>'System.IO.FileNotFoundException'</code>
    Could not find file <code>'C:\Users\sc\AppData\Local\Temp\\work\Rdp000001.rpt'</code>.</p>
  </blockquote>
  
  <p>Also, <code>if (fil.Exists)</code> returns false.</p>