title: Trying to delete an XML file throws "The process cannot access the file..." error
body: <p>I have a little app that is supposed to read through an XML document that the user uploads. If the file doesn't have the proper nodes, the file is deleted and the user is notified.</p>
  
  <p>However, the file is always locked when I try to delete it, both in code and through windows explorer. It stays locked until I refresh the page in IE.</p>
  
  <pre><code>myDoc.Load(FileUpload2.FileContent);
  string XMLpath = Server.MapPath(ConfigurationSettings.AppSettings["PDFLocation"]) + FileUpload2.FileName;
  myDoc.Save(XMLpath);
  file = new FileInfo(XMLpath);
  
  //here I check if the file is valid. If not, delete
  
  file.Delete(); //This is where it throws the "cannot access the file" error
  </code></pre>
  
  <p>the full text of the error:</p>
  
  <pre><code>The process cannot access the file 'C:\project\files\file.xml' because it is being used by another process. 
  </code></pre>
  
  <p>I tried putting in <code>FileUpload2.FileContent.Dispose();</code> and <code>FileUpload2.Dispose();</code> before the delete statement, but no luck.</p>
  
  <p>How do I release the file for deletion?</p>