Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error Deleting File or Folder

Error Deleting File or Folder

Scheduled Pinned Locked Moved ASP.NET
helpsysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pavya_Cool
    wrote on last edited by
    #1

    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

    S N 2 Replies Last reply
    0
    • P pavya_Cool

      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

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      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... "

      1 Reply Last reply
      0
      • P pavya_Cool

        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

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        pavya_Cool wrote:

        oreach (FileInfo FI in DirInfo.GetFiles())

        Fileinfo class has opened the file. So try the following

        foreach(string strFileName in Directory.GetFiles(YourPath))
        {
        File.Delete(strFileName);
        }


        My Website | Ask smart questions

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups