Why is access to the path denied?

前端 未结 29 1068
刺人心
刺人心 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 16:02

    According to File.Delete Method...

    An UnauthorizedAccessException means one of 4 things:

    • The caller does not have the required permission.
    • The file is an executable file that is in use.
    • Path is a directory.
    • Path specified a read-only file.
    0 讨论(0)
  • 2020-11-22 16:02

    The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.

    I hit the same thing. Check to ensure that the file is NOT HIDDEN.

    0 讨论(0)
  • 2020-11-22 16:05

    If you're using BitDefender there's a good chance its Safe Files feature blocked your operation. This is a form of Ransomware protection that comes with some of its more advanced versions.

    Make sure to grant your application access in BitDefender and try again.

    Some more details can be found in this BitDefender support page.

    0 讨论(0)
  • 2020-11-22 16:05

    I too faced the same problem when trying to do this after deployment at server:

    dirPath = Server.MapPath(".") + "\\website\\" + strUserName;
    if (!Directory.Exists(dirPath))
    {
        DirectoryInfo DI = Directory.CreateDirectory(dirPath);
    }
    string filePath = Server.MapPath(".") + "\\Website\\default.aspx";
    File.Copy(filePath, dirPath + "\\default.aspx", true);
    File.SetAttributes(dirPath + "\\default.aspx", FileAttributes.Normal);
    

    I granted permission in IIS to other group including administrator and my problem got solved.

    0 讨论(0)
  • 2020-11-22 16:06

    I had the exact error when deleting a file. It was a Windows Service running under a Service Account which was unable to delete a .pdf document from a Shared Folder even though it had Full Control of the folder.

    What worked for me was navigating to the Security tab of the Shared Folder > Advanced > Share > Add.

    I then added the service account to the administrators group, applied the changes and the service account was then able to perform all operations on all files within that folder.

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