Why is access to the path denied?

前端 未结 29 1091
刺人心
刺人心 2020-11-22 15:25

I am having a problem where I am trying to delete my file but I get an exception.

if (result == \"Success\")
{
     if (FileUpload.HasFile)
     {
         t         


        
相关标签:
29条回答
  • 2020-11-22 15:48

    I was trying to use System.IO.File.OpenWrite(path)

    and it did not work because I was only passing OpenWrite() a path to a directory, but it requires a path all the way to the file you want to write. So a full path including the filename.extension at the end needs to be passed into OpenWrite to avoid UnauthorizedAccessException

    0 讨论(0)
  • 2020-11-22 15:52

    Check your files properties. If the read-only is checked, uncheck it. This was my personal issue with the UnauthorizedAccessException.

    0 讨论(0)
  • 2020-11-22 15:52

    I also ran into this post as dealing with the same issue. Looks like the file is in use and hence not able to write to it. Though not able to figure it out, which process is using it. Signed out the other user who was logged in in that box, dont see any users who is holding it. Any quick tips regarding on how to find the same.

    Thanks, Lakshay (developer)

    0 讨论(0)
  • 2020-11-22 15:53

    An UnauthorizedAccessException exception is thrown when the operating system denies access because of an I/O error or a security error.

    If you are attempting to access a file or registry key, make sure it is not read-only.

    0 讨论(0)
  • 2020-11-22 15:53

    I got this error and solved it in just a moment. Don't know why all of my folders are read-only,I cancelled the read-only and apply it. However, it is still read-only. So I moved the file into the root folder, it works - so weird.

    0 讨论(0)
  • 2020-11-22 15:53

    Be aware that if you are trying to reach a shared folder path from your code, you dont only need to give the proper permissions to the physicial folder thru the security tab. You also need to "share" the folder with the corresponding app pool user thru the Share Tab

    0 讨论(0)
提交回复
热议问题