Ошибка access to the path is denied

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

if (result == "Success")
{
     if (FileUpload.HasFile)
     {
         try
         {
              File.Delete(Request.PhysicalApplicationPath + app_settings.login_images + txtUploadStatus.Text);
              string filename = Path.GetFileName(btnFileUpload.FileName);
              btnFileUpload.SaveAs(Request.PhysicalApplicationPath + app_settings.login_images + filename);
         }
         catch (Exception ex)
         {
               Message(ex.ToString());
         }
      }
}

Also I should note that the folder I am trying to delete from has full control to network services.

The full exception message is:

System.UnauthorizedAccessException: Access to the path ‘C:UsersgowdynDocumentsVisual Studio 2008Projectshybridhybridtemp_loginimagesenviromental.jpg’ is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.Delete(String path) at hybrid.User_Controls.Imgloader_Add_Edit_Tbl.btnUpdate_Click(Object sender, EventArgs e) in C:UsersgowdynDocumentsVisual Studio 2008ProjectshybridhybridUser_ControlsImgloader_Add_Edit_Tbl.ascx.cs:line 242

Any ideas?

durron597's user avatar

durron597

31.9k17 gold badges99 silver badges156 bronze badges

asked Jan 11, 2012 at 14:58

nick gowdy's user avatar

nick gowdynick gowdy

6,12124 gold badges87 silver badges154 bronze badges

4

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.

Feidr Corn's user avatar

answered Jul 17, 2014 at 6:15

CrazyTim's user avatar

8

I also had the problem, hence me stumbling on this post. I added the following line of code before and after a Copy / Delete.

Delete

File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);

Copy

File.Copy(file, dest, true);
File.SetAttributes(dest, FileAttributes.Normal);

answered Jul 17, 2012 at 13:12

Riaan's user avatar

RiaanRiaan

3,4134 gold badges30 silver badges36 bronze badges

12

This is an old issue, but I ran into it while searching. Turns out that I was missing the actual filename component in the save path for SaveAs…

string uploadPath = Server.MapPath("~/uploads");
file.SaveAs(uploadPath); // BAD
file.SaveAs(Path.Combine(uploadPath, file.FileName)); // GOOD

vakio's user avatar

vakio

3,1341 gold badge22 silver badges46 bronze badges

answered Dec 10, 2013 at 23:44

Andrew Edvalson's user avatar

Andrew EdvalsonAndrew Edvalson

7,6385 gold badges26 silver badges24 bronze badges

0

When a user tries to connect to your Web site, IIS assigns the connection to the IUSER_ComputerName account, where ComputerName is the name of the server on which IIS is running. By default, the IUSER_ComputerName account is a member of the Guests group. This group has security restrictions. Try to grand access to IUSER_ComputerName to that folder

Here is very good described answer about IIS security

Hope this helps

Community's user avatar

answered Jan 11, 2012 at 15:05

Arsen Mkrtchyan's user avatar

Arsen MkrtchyanArsen Mkrtchyan

49.7k32 gold badges147 silver badges183 bronze badges

1

I got the error because I didn’t realize that the destination should be a file. I had a folder as the second parameter (which works in cmd). and I got Unhandled Exception: System.UnauthorizedAccessException: Access to the path is denied. because C# File.Move wants a file there, not just for the first parameter, but for the second too, and so if you put a directory as second parameter, it’s trying to write a file like c:crp when you have a directory called c:crp.

this would be incorrect File.Move(args[0],"c:\crp");

So, this would be correct File.Move(args[0],"c:\crp\a.a");

The same goes for File.Copy

OrionMD's user avatar

OrionMD

3491 gold badge7 silver badges13 bronze badges

answered Apr 26, 2016 at 11:11

barlop's user avatar

barlopbarlop

12.7k8 gold badges79 silver badges107 bronze badges

1

Right-click on Visual studio and click Run as Administrator

Thanks for +1

answered Feb 24, 2016 at 15:59

Alexander Zaldostanov's user avatar

1

If this is an IIS website that is having the problem, check the Identity property of the advanced settings for the application pool that the site or application uses. You may find that it is set to ApplicationPoolIdentity, and in that case then this is the user that will have to have access to the path.

Or you can go old style and simply set the Identity to Network Service, and give the Network Service user access to the path.

Mike Ellis's user avatar

answered Aug 21, 2014 at 8:11

Bjørn Otto Vasbotten's user avatar

same issue for me too,
I was pointing the folder instead of file.

so make sure in path, give path+filename

System.IO.File.WriteAllBytes("path", bytearray);

pushkin's user avatar

pushkin

9,45015 gold badges51 silver badges93 bronze badges

answered Nov 16, 2018 at 14:21

jineesh vp's user avatar

jineesh vpjineesh vp

711 silver badge2 bronze badges

0

You need to modify the privileges of the folder you’re trying to delete from/save to. Right-click on the containing folder and use the Security tab to permit modify rights for the user your application runs under.

answered Jan 11, 2012 at 15:04

Brissles's user avatar

BrisslesBrissles

3,83323 silver badges31 bronze badges

3

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.

answered Jun 19, 2018 at 4:13

reza.Nikmaram's user avatar

I have also faced this issue when my window service started throwing the exception

System.UnauthorizedAccessException: Access to the path "C:\Order\Media
44aa4857-3bac-4a18-a307-820450361662.mp4" is denied.

So as a solution, I checked the user account associated with my service, as shown in below screen capture

enter image description here

So in my case it was NETWORK SERVICE

And then went to the folder properties to check if the associated user account also exists under their permission tab. It was missing in my case and when I added it and it fixed my issue.

For more information please check the below screen capture

enter image description here

answered Aug 2, 2018 at 12:07

Jitender Kumar's user avatar

Jitender KumarJitender Kumar

2,3494 gold badges29 silver badges42 bronze badges

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.

Ghasem's user avatar

Ghasem

14.2k20 gold badges136 silver badges169 bronze badges

answered Jun 28, 2012 at 20:16

Ron H's user avatar

Ron HRon H

751 silver badge5 bronze badges

1

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

answered Jul 3, 2014 at 14:26

user3238433's user avatar

I was facing this error because

Sometimes when I Combine the path with File Name and FileName = ""

It become Path Directory not a file which is a problem as mentioned above

so you must check for FileName like this

if(itemUri!="")
        File.Delete(Path.Combine(RemoteDirectoryPath, itemUri));

Community's user avatar

answered Jun 21, 2016 at 9:57

Basheer AL-MOMANI's user avatar

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.

TomServo's user avatar

TomServo

7,1985 gold badges29 silver badges46 bronze badges

answered Jun 21, 2016 at 2:51

MOLLMY's user avatar

1

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

answered Jan 22, 2019 at 19:03

SeanMC's user avatar

SeanMCSeanMC

1,9251 gold badge22 silver badges33 bronze badges

In my case the problem was Norton. My in-house program doesn’t have the proper digital signature and when it tried to delete a file it gave the UnauthorizedAccessException.

enter image description here

If it give you a notification, you can handle it from there. In my case it didn’t give a notification that I noticed. So here’s how to keep Norton from blocking the program.

  1. Open Norton
  2. Click the down arrow
  3. Click History
  4. Find activity by program
  5. Click More Options
  6. Click Exclude Process

answered Feb 14, 2020 at 18:11

D_Bester's user avatar

D_BesterD_Bester

5,7035 gold badges34 silver badges77 bronze badges

To solve this problem, I follow the Scot Hanselman approach at Debugging System.UnauthorizedAccessException (often followed by: Access to the path is denied) article, the code with example is bellow:

class Program
{
    static void Main(string[] args)
    {
        var path = "c:\temp\notfound.txt";
        try
        {
            File.Delete(path);
        }
        catch (UnauthorizedAccessException)
        {
            FileAttributes attributes = File.GetAttributes(path);
            if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                attributes &= ~FileAttributes.ReadOnly;
                File.SetAttributes(path, attributes);
                File.Delete(path);
            }
            else
            {
                throw;
            }
        }
    }
}

answered Jun 3, 2020 at 1:42

Antonio Leonardo's user avatar

Antonio LeonardoAntonio Leonardo

1,8051 gold badge8 silver badges18 bronze badges

I had the same problem on a newly moved website on a shared server. Solved through the web host panel (DotNetPanel) setting true the «allow write permissions». So if you are in a shared server before reviewing all code worth taking a look at the server configuration and could save you a lot of time.

answered Jul 19, 2013 at 19:31

Drakell's user avatar

DrakellDrakell

1501 silver badge10 bronze badges

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

answered Jul 22, 2013 at 20:20

Kacho's user avatar

KachoKacho

211 bronze badge

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.

answered Aug 1, 2018 at 10:02

LuTheZy's user avatar

For those trying to make a UWP (Universal Windows) application, file permissions are much more restricted, and in general is deny by default. It also supersedes the system user permissions. You will basically only have access to files in either

  • Your install location
  • Your AppData location
  • Files selected through the File or Folder picker
  • Locations requested in your App Manifest

You can read more here for details => https://learn.microsoft.com/en-us/windows/uwp/files/file-access-permissions

answered Jan 30, 2019 at 21:12

Tezra's user avatar

TezraTezra

8,3363 gold badges28 silver badges65 bronze badges

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.

answered Feb 4, 2019 at 21:22

Vlad Schnakovszki's user avatar

Vlad SchnakovszkiVlad Schnakovszki

8,3866 gold badges79 silver badges113 bronze badges

In my case it was my AVG anti-virus that triggered the exception.

I added my VS Projects directory to the «Allowed» list. And I had to add the executable to the AVG exceptions list after I copied the .exe to my App directory.

benhorgen's user avatar

benhorgen

1,9181 gold badge33 silver badges37 bronze badges

answered Feb 8, 2021 at 18:00

OneWileyDog's user avatar

1

I’ve had the same problem and I’ve managed to get it working by changing the partition on which the file will be saved. So, on line 5 I’ve changed @»C:» to be @»D:» and that resolved the problem.

static void SaveVideoToDisk(string link)
{
    var youTube = YouTube.Default; // starting point for YouTube actions
    var video = youTube.GetVideo(link); // gets a Video object with info about the video
    File.WriteAllBytes(@"D:" + video.FullName, video.GetBytes());
}

answered Apr 30, 2021 at 8:25

Kristiyan Ivanov's user avatar

After migrating from Visual Studio 2017 to Visual Studio 2019 I faced two exceptions with two of my applications which run properly under Visual Studio 2017:

  • System.UnauthorizedAccessException
  • System.ArgumentException

It turned out that I had to add the executables of the two applications to the allowed apps of Avast Antivirus.

answered Oct 12, 2021 at 10:31

Pollitzer's user avatar

PollitzerPollitzer

1,5603 gold badges18 silver badges28 bronze badges

2

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.

eeerahul's user avatar

eeerahul

1,6294 gold badges27 silver badges38 bronze badges

answered Feb 1, 2012 at 12:14

Manish Singh's user avatar

In my particular case I was repeatedly creating and deleting 10000 folders. It seems to me that the problem was in that although the method Directory.Delete(path, true) returns, the underling OS mechanism may still be deleting the files from the disk. And when I am starting to create new folders immediately after deletion of old ones, some of them are still locked because they are not completely deleted yet. And I am getting System.UnauthorizedAccessException: «Access to the path is denied».

enter image description here

Using Thread.Sleep(5000) after Directory.Delete(path, true) solves that problem. I absolutely agree that this is not safe, and I am not encouraging anyone to use it. I would love to here a better approach to solve this problem to improve my answer. Now I am just giving an idea why this exception may happen.

class Program
{
    private static int numFolders = 10000;
    private static string rootDirectory = "C:\1";

    static void Main(string[] args)
    {
        if (Directory.Exists(rootDirectory))
        {
            Directory.Delete(rootDirectory, true);
            Thread.Sleep(5000);
        }

        Stopwatch sw = Stopwatch.StartNew();
        CreateFolder();
        long time = sw.ElapsedMilliseconds;

        Console.WriteLine(time);
        Console.ReadLine();
    }

    private static void CreateFolder()
    {
        var one = Directory.CreateDirectory(rootDirectory);

        for (int i = 1; i <= numFolders; i++)
        {
            one.CreateSubdirectory(i.ToString());
        }
    }
}

OrionMD's user avatar

OrionMD

3491 gold badge7 silver badges13 bronze badges

answered Aug 21, 2018 at 6:37

Aleksei Mialkin's user avatar

Aleksei MialkinAleksei Mialkin

2,2271 gold badge27 silver badges25 bronze badges

First just check the path if the colon(:) character is missing or not after the drive letter. If colon is not missing then you can check if access/write permission is granted for that path.
I had the same issue and i was only missing the colon, permission and everything else was fine.

C:folderpath

will work fine but,

Cfolderpath .........(missing colon)

will give you access denial error.

OrionMD's user avatar

OrionMD

3491 gold badge7 silver badges13 bronze badges

answered Nov 14, 2018 at 13:50

Vijay Dodamani's user avatar

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)

answered Sep 14, 2019 at 1:41

Lakshay Gupta's user avatar

1

  • Remove From My Forums
  • Question

  • I’m on windows 7 creating a desktop aplication in Visual C# 2010.
    The error’s produced here:

    void Copymove(string file) 
    {
     File.Copy(Environment.GetFolderPath(Environment.SpecialFold er.MyDocuments), "../../contenidos/" + file);
    }

    The exact error:
    Access to the path ‘C:UsersDanielDocuments’ is denied.

    I’ve already tried modifying the app.manifest and it does not work… It’s been about 5 hours i’ve been trying
    to fix this. Any ideas?

    Thanks in advance.

Answers

  • On 6/24/2012 4:29 PM, belohlavek wrote:

    > Did everything you said and still can’t change the read only setting on

    > the folder I want to access.

    There are two user groups on the folder. The Admin group and your

    usernamemachine-nameusername and if the those two accounts don’t match

    in the permissions for write access, then it’s going to be access

    denied, because usernamemachine-nameusername (that’s your username

    account) doesn’t have the same rights as admin and admin is being

    superseded by user account.

    Your user account is in two groups, and one is in conflict with the

    other, and they must both match. That’s just the way it is in Vista and

    Win 7, which are not XP.

    • Marked as answer by

      Monday, July 9, 2012 6:25 AM

Debugging System.UnauthorizedAccessException (often followed by: Access to the path is denied)

It’s time for another post in our series about Debugging common .NET exceptions. Today, I want to introduce you to System.UnauthorizedAccessException. The exception is typically caused by an IO error, but other issues like security restrictions are also known to utilize this error. Let’s dig in!

Debugging System.UnauthorizedAccessException

Handling the error

Catching the exception is straightforward. Let’s create a small program to provoke and catch this error. Before writing code, I’ll create a text file named c:tempreadonly.txt. Once created, right-click the file, select Properties, and enable the Read-only checkbox. This causes, surprise!, the file to be read-only. Now for the code:

class Program
{
    static void Main(string[] args)
    {
        var path = "c:\temp\readonly.txt";
        try
        {
            File.Delete(path);
        }
        catch (UnauthorizedAccessException e)
        {
            Console.WriteLine(e);
        }
    }
}

As shown in the code, we simply catch the UnauthorizedAccessException and log it to the console.

Debugging the error

UnauthorizedAccessException contains no additional status or error code property so that you can figure out what is going on. The only indication is to look in the Message property, which in most cases looks similar to this:

Access to the path 'c:tempnotfound.txt' is denied.

So, why is access denied? We can start by excluding some scenarios I’ve seen people suggest as wrong answers on StackOverflow:

  1. If a file was not found on disk (this doesn’t throw the UnauthorizedAccessException).
  2. If a file is currently locked by another program (this throws an IOException).
  3. If a file is being blocked by Windows.
  4. Accessing a file in a non-existing directory (this throws a DirectoryNotFoundException).

The following sections point out different causes of the exception.

A read-only file

Probably the easiest thing to check when dealing with files is to right-click the file and check if the Read-only checkbox is checked:

File properties

File properties

Simply uncheck Read-only and try again.

If you want to, you can unlock a read-only file in C# and try again:

class Program
{
    static void Main(string[] args)
    {
        var path = "c:\temp\notfound.txt";
        try
        {
            File.Delete(path);
        }
        catch (UnauthorizedAccessException)
        {
            FileAttributes attributes = File.GetAttributes(path);
            if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                attributes &= ~FileAttributes.ReadOnly;
                File.SetAttributes(path, attributes);
                File.Delete(path);
            }
            else
            {
                throw;
            }
        }
    }
}

Current user doesn’t have access to a file

Another instance of the UnauthorizedAccessException is caused by issues with the user executing the program. If not running in elevated mode (Admin rights in Windows), the current user won’t have access to various Windows directories like c:Windows and c:Program Files. A simple fix for this error is to run the program as an Administrator.

If the error is generated by a Windows Service, open Services, locate your service on the list and double-click it. On the Log On tab, make sure your service is configured with a user with access to the resource causing the exception. Services running as Network Service have very limited access to local resources. I would recommend you chat with your systems administrator to decide if you want to go with the default service users or create a custom one with custom permissions.

Access to file system from IIS

If you are experiencing this error while browsing a website hosted on IIS, it’s a similar error to the one described above. A .NET application hosted on IIS uses the application pool user as a default to access files on the file system.

To fix this, add the IIS AppPool user to the root folder of your application by right-clicking the folder and selecting Properties. Select the Security tab and add the IIS AppPool<AppPoolName> user:

Select Users or Groups

Select Users or Groups

Like Windows Services, you can also decide to create a custom user to access the file system from IIS. Create a new Windows (or AD) user and click your site inside the IIS Manager. From the Actions window click Basic Settings. Finally, click the Connect as button and input the new user below Specific user:

Connect As

Connect As

This example illustrates the scenario where the IIS user doesn’t have access to the folder containing the website files. You may also experience other scenarios where Windows authentication is used to control individual website users’ access to one or more files on the file system. In these cases, you want to re-use the example above to catch the exception in your code and inform the website user in a better way than showing an IIS error page.

Also make sure to read the other posts in this series: Debugging common .NET exception.

elmah.io: Error logging and Uptime Monitoring for your web apps

This blog post is brought to you by elmah.io. elmah.io is error logging, uptime monitoring, deployment tracking, and service heartbeats for your .NET and JavaScript applications. Stop relying on your users to notify you when something is wrong or dig through hundreds of megabytes of log files spread across servers. With elmah.io, we store all of your log messages, notify you through popular channels like email, Slack, and Microsoft Teams, and help you fix errors fast.

elmah.io app banner

See how we can help you monitor your website for crashes
Monitor your website

When I run:

docker run --rm `
>>   -e SERVER_NAME=my-domain `
>>   -e IP_ADDRESSES=$ips,public-ip `
>>   -v "C:ProgramDatadocker:C:ProgramDatadocker" `
>>   -v "$env:USERPROFILE.docker:C:UsersContainerAdministrator.docker" `
>>   stefanscherer/dockertls-windows

I have this error:

mkdir : Access to the path 'C:ProgramDatadockercerts.d' is denied.
At C:generate-certs.ps1:17 char:7
+       mkdir $dir
+       ~~~~~~~~~~
+ CategoryInfo          : PermissionDenied: (C:ProgramDatadockercerts.d:String) [New-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

And, when I run:

mkdir ~.docker
docker run --rm `
>>   -e SERVER_NAME=my-domain `
>>   -e IP_ADDRESSES=$ips,public-ip `
>>   -v "$env:USERPROFILE.docker:C:UsersContainerAdministrator.docker" `
>>   stefanscherer/dockertls-windows

I have this output:

    Directory: C:ProgramDatadocker

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         4/29/2019  2:45 AM                certs.d
d-----         4/29/2019  2:45 AM                config

    Directory: C:UsersContainerUser

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         4/29/2019  2:45 AM                .docker

    Directory: C:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         4/29/2019  2:45 AM                DockerSSLCARoot

=== Generating CA private password

=== Writing out private key password

=== Generating CA private key
Generating RSA private key, 4096 bit long modulus
......................++
......................................................++
e is 65537 (0x10001)

=== Generating CA public key - expires in 365 days

=== Reading in CA Private Key Password

=== Generating Server private key
server-key.pem: Permission denied
1204969060:error:02FFF00D:system library:func(4095):Permission denied:bio/bss_file.c:255:fopen('server-key.pem', 'w')
1204969060:error:20FFF002:BIO routines:CRYPTO_internal:system lib:bio/bss_file.c:257:

=== Generating Server signing request
Error opening Private Key server-key.pem
747847294:error:02FFF002:system library:func(4095):No such file or directory:bio/bss_file.c:255:fopen('server-key.pem', 'r')
747847294:error:20FFF002:BIO routines:CRYPTO_internal:system lib:bio/bss_file.c:257:
unable to load Private Key

=== Signing Server request
Out-File : Access to the path 'C:extfile.cnf' is denied.
At C:generate-certs.ps1:64 char:44
+ ... AltName = " + ($san -join ',') | Out-File extfile.cnf -Encoding Ascii
+                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

How can I resolve this error?! What do I need to do?

I’m on windows server 2019, at aws-ec2.

Thankful!

In your development career, you will get this error very often and sometimes you may not be able to resolve it. So, in this post, I will tell you how to approach this error. 

Resolving «Access Path is Denied» error 

First of all, what do you need to check to see if the path has permissions or not? For this, let’s see below how you can do this.

  1. To grant ASP.NET access to a file, right-click the file in Explorer, choose «Properties», and select the Security tab. Click «Add» to add the appropriate user or group. Highlight the ASP.NET account and check the boxes for the desired access.

    You can either add «IISUSERS» or add «EVERYONE» (which is less secure) and give them full rights to remove this error. 

  2. Before opening Visual Studio, right-click on your Visual Studio icon and run it as an administrator. Try again to run your code. If your problem is not resolved, do the following.
    1. Right-click on your directory that you want to access and select «Properties».
    2. Select the «Security» tab.
    3. Click on the «Advanced» button.
    4. Select the «Owner» tab.
    5. Select the owner (MACHINENAMEAdministrators), check the «Replace owner on subcontainers and objects» and click OK.

So by using these two approaches, you can resolve this access denied error.

Hope this will help you someday!!!

Понравилась статья? Поделить с друзьями:
  • Ошибка access denied в браузере
  • Ошибка access denied to remote resource
  • Ошибка access denied for user localhost using password yes
  • Ошибка access denied for user localhost to database
  • Ошибка access control allow origin header is present