title: ASP.NET C#: Best way to delete a file (image) from windows based server
body: <p>I am developing a website where user can upload images. I am saving images into a FTP folder (not in db) and the details of it in the database (file name, path, etc).</p>
  
  <p>I have noticed that when working on localhost the following code works just fine, it doesn't give me any error. But when uploaded to server(with windows hosting plan), it doesn't delete the file and gives me error that: <code>cannot delete the file because it is used by another process.</code></p>
  
  <p>I have made sure that the directory has suitable file permissions but still it does not delete it. and strange enough, when i use FTP client to delete it manually, it locks the file and doesn't allow me to delete from there. I have to recycle the app pool to do so.</p>
  
  <p>I am looking for best way to delete file from windows based server when you have full path to the file.</p>
  
  <p>The code I have used on localhost is (which when uploaded to server, it breaks the rest of the code):</p>
  
  <pre><code>if (File.Exists(path))
  {
      File.Delete(path);
  }
  </code></pre>
  
  <p>Thank you.</p>