Error: An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

后端 未结 4 869
粉色の甜心
粉色の甜心 2021-01-02 23:34

This is the part that crashes and gives me this error is when I try to copy a file to a certain location.

string startupDirectory = \"C:\\\\Users\\\\Tyler\\\         


        
4条回答
  •  清酒与你
    2021-01-02 23:45

    Try

    public static void Copy(string sourceFileName, string destFileName);
    

    First overload is source 2nd overload is destination i think reason might be this

    File.Copy("Startup.exe",startupDirectory);
    

    Try setting the access permissions to "Full control" for the .Net user from where you are reading/saving the files.

    For Access Denied Error in IIS server for particular file , please follow the below steps

    1- Goto to C:\\Users\\Tyler\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup
    
    2- Right click on your file -> Properties -> Pop Up of User properties appears -> click on Security tab-> click on Edit -> select Users-> tick on Allow Full Control -> Click Ok
    

    This will surely solve the Access denied problem

    An UnauthorizedAccessException means one of 3 things:

    • The caller does not have the required permission.
    • path is a directory.
    • path specified a read-only file.

提交回复
热议问题