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).
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: cannot delete the file because it is used by another process.
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.
I am looking for best way to delete file from windows based server when you have full path to the file.
The code I have used on localhost is (which when uploaded to server, it breaks the rest of the code):
if (File.Exists(path))
{
File.Delete(path);
}
Thank you.