I found a solution why iam gets the "access denied" exception in my application.
Since iam deletes the file inside the application through the code, I need to have the โAdministratorโ privilege.
One way is to manually enter the user into the system as an administrator. But this is not the best option.
Another way is to create an application manifest file in your project and set the level as "administartor".
Creating an application manifest โ Right-click on the project-> Add new item โ Select the App Manifest option in the right pane-> Click ok
Open the manifest file and change the level to "requireAdministartor".
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
This will solve the problem during application startup, and prompt the user to run it as an administrator.
Hope this will be useful to someone in the future. :) Thank you guys for your support.
source share