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. Access to the path is denied -when trying to delete files

Access to the path is denied -when trying to delete files

Scheduled Pinned Locked Moved ASP.NET
comhelp
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.
  • R Offline
    R Offline
    Ramkumar_S
    wrote on last edited by
    #1

    Hi All string FilePath = strphysicalpath + @"Documents\TempReports"; DirectoryInfo di = new DirectoryInfo(FilePath); di.Attributes = FileAttributes.Normal; foreach (string fileName in System.IO.Directory.GetFiles(FilePath)) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); fileInfo.Attributes = FileAttributes.Normal; } string[] filePaths = Directory.GetFiles(FilePath); foreach (string filePath in filePaths) { File.Delete(filePath); } I use this code to delete all my files in the Folder, but I am getting "Access to the path is denied" Please help.

    Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com

    J R 2 Replies Last reply
    0
    • R Ramkumar_S

      Hi All string FilePath = strphysicalpath + @"Documents\TempReports"; DirectoryInfo di = new DirectoryInfo(FilePath); di.Attributes = FileAttributes.Normal; foreach (string fileName in System.IO.Directory.GetFiles(FilePath)) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); fileInfo.Attributes = FileAttributes.Normal; } string[] filePaths = Directory.GetFiles(FilePath); foreach (string filePath in filePaths) { File.Delete(filePath); } I use this code to delete all my files in the Folder, but I am getting "Access to the path is denied" Please help.

      Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      if it's the second file, you need to release the first file.

      fileInfo = NULL;

      1 Reply Last reply
      0
      • R Ramkumar_S

        Hi All string FilePath = strphysicalpath + @"Documents\TempReports"; DirectoryInfo di = new DirectoryInfo(FilePath); di.Attributes = FileAttributes.Normal; foreach (string fileName in System.IO.Directory.GetFiles(FilePath)) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); fileInfo.Attributes = FileAttributes.Normal; } string[] filePaths = Directory.GetFiles(FilePath); foreach (string filePath in filePaths) { File.Delete(filePath); } I use this code to delete all my files in the Folder, but I am getting "Access to the path is denied" Please help.

        Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com

        R Offline
        R Offline
        RaviRanjanKr
        wrote on last edited by
        #3

        Always wrap your code in "Pre" tag, because it will give better readability and accessibility.

        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