Error Deleting File or Folder
-
Hi to all, I am trying to delete all the files in a specified folder in my project. for that i have written the following function.... ============================================================================== Code ============================================================================== public void DeleteTempFiles() { DirectoryInfo DirInfo = new DirectoryInfo(Server.MapPath("~/temp/")); if(DirInfo.Exists) { foreach (FileInfo FI in DirInfo.GetFiles()) { FI.Delete(); } } } ============================================================================== But whenever i am running the program it gives the error as.... Error Deleting File or Folder Cannot delete : It is being used by another person or program. Close any program that might be using the file and try again. ..... Anybody help me to solve this problem.
Pravin
-
Hi to all, I am trying to delete all the files in a specified folder in my project. for that i have written the following function.... ============================================================================== Code ============================================================================== public void DeleteTempFiles() { DirectoryInfo DirInfo = new DirectoryInfo(Server.MapPath("~/temp/")); if(DirInfo.Exists) { foreach (FileInfo FI in DirInfo.GetFiles()) { FI.Delete(); } } } ============================================================================== But whenever i am running the program it gives the error as.... Error Deleting File or Folder Cannot delete : It is being used by another person or program. Close any program that might be using the file and try again. ..... Anybody help me to solve this problem.
Pravin
pavya_Cool wrote:
But whenever i am running the program it gives the error as.... Error Deleting File or Folder Cannot delete : It is being used by another person or program. Close any program that might be using the file and try again.
As Error message is saying might be your application is using some of those files
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Hi to all, I am trying to delete all the files in a specified folder in my project. for that i have written the following function.... ============================================================================== Code ============================================================================== public void DeleteTempFiles() { DirectoryInfo DirInfo = new DirectoryInfo(Server.MapPath("~/temp/")); if(DirInfo.Exists) { foreach (FileInfo FI in DirInfo.GetFiles()) { FI.Delete(); } } } ============================================================================== But whenever i am running the program it gives the error as.... Error Deleting File or Folder Cannot delete : It is being used by another person or program. Close any program that might be using the file and try again. ..... Anybody help me to solve this problem.
Pravin
pavya_Cool wrote:
oreach (FileInfo FI in DirInfo.GetFiles())
Fileinfo
class has opened the file. So try the followingforeach(string strFileName in Directory.GetFiles(YourPath))
{
File.Delete(strFileName);
}