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. File.Delete does not work

File.Delete does not work

Scheduled Pinned Locked Moved ASP.NET
questionasp-nethelp
5 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
    peacefulmember
    wrote on last edited by
    #1

    I want to delete some files from my application. For this I am using System.IO.File.Delete. It gives me error "Access to Path 'C:\EmployeeData\EmployeeJun.htm' is denied." I did find some articles explaining that account should have privileges to the path or file. I verified that ASPNET account had read and write permission to the folder and to the file (inherited permission from parent). Any idea what is missing here. In addition, I have web service in application that can delete the same file from within the application. In case account is missing permissions to the file, how File.Delete can delete the same file from web service? Please explain. Thanks in advance.

    C K 2 Replies Last reply
    0
    • P peacefulmember

      I want to delete some files from my application. For this I am using System.IO.File.Delete. It gives me error "Access to Path 'C:\EmployeeData\EmployeeJun.htm' is denied." I did find some articles explaining that account should have privileges to the path or file. I verified that ASPNET account had read and write permission to the folder and to the file (inherited permission from parent). Any idea what is missing here. In addition, I have web service in application that can delete the same file from within the application. In case account is missing permissions to the file, how File.Delete can delete the same file from web service? Please explain. Thanks in advance.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Your ASP.NET application cannot access files above the application root. This is by design.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      P 1 Reply Last reply
      0
      • P peacefulmember

        I want to delete some files from my application. For this I am using System.IO.File.Delete. It gives me error "Access to Path 'C:\EmployeeData\EmployeeJun.htm' is denied." I did find some articles explaining that account should have privileges to the path or file. I verified that ASPNET account had read and write permission to the folder and to the file (inherited permission from parent). Any idea what is missing here. In addition, I have web service in application that can delete the same file from within the application. In case account is missing permissions to the file, how File.Delete can delete the same file from web service? Please explain. Thanks in advance.

        K Offline
        K Offline
        kubben
        wrote on last edited by
        #3

        If the aspnet user has access you also need to give IIS_WPG access, then it should work. Ben

        1 Reply Last reply
        0
        • C Christian Graus

          Your ASP.NET application cannot access files above the application root. This is by design.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          P Offline
          P Offline
          peacefulmember
          wrote on last edited by
          #4

          Thank you for reply. File is not above the application root but under application root. Like I stated before, I can delete the file from the web service running on the server (personal web server here) and invoked from the application. File (also created from the application) has Read, Write and Read & Execute permissions already. I just tried giving Modify permission to the file and delete it from aspx page. It worked. I am confused!! Kubben, what for is IIS_WPG account?

          K 1 Reply Last reply
          0
          • P peacefulmember

            Thank you for reply. File is not above the application root but under application root. Like I stated before, I can delete the file from the web service running on the server (personal web server here) and invoked from the application. File (also created from the application) has Read, Write and Read & Execute permissions already. I just tried giving Modify permission to the file and delete it from aspx page. It worked. I am confused!! Kubben, what for is IIS_WPG account?

            K Offline
            K Offline
            kubben
            wrote on last edited by
            #5

            IIS_WPG is the iis worker process group. Any user or identity that you are trying to use to be the indentity of the application pool also need to be in the IIS_WPG group. Thinking about it aspnet user would already be in this group. Still the identity of your app pool it probably network service. That group most likely doesn't have rights to delete the file. Ben

            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