System.UnauthorizedAccessException: Access to the path "..." is denied System.UnauthorizedAccessException: Access to the path "..." is denied wpf wpf

System.UnauthorizedAccessException: Access to the path "..." is denied


When installing an application the installer usually asks for administrative privileges. If the user chooses "Yes" the program will run and have read and write access to a larger variety of paths than what a normal user has. If the case is such that the installer did not ask for administrative privileges, it might just be that ClickOnce automatically runs under some sort of elevated privileges.

I'd suggest you write to the local appdata folder instead, but if you feel you really want to write to the very same directory as your application you must first run your app with administrator privileges.

To make your application always ask for administrator privileges you can modify your app's manifest file and set the requestedExecutionLevel tag's level attribute to requireAdministrator:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

You can read a bit more in How do I force my .NET application to run as administrator?


I was running a program that would generate file. The destination folder was read only. And it would crash with the error. Removing the read-only attribute using folder properties resolved the error.


First, if you need to write any data you should use the Environment.SpecialFolder enumeration.

Second, do not write to any folder where the application is deployed because it is usually read only for applications. You probably want to write to the ApplicationData or LocalApplicationData enumerations.