I am trying to write a file to a directory that exists and is created by me in G:\\
i.e. not a system directory or in root drive
like this
File.WriteAllBytes(directoryPath.Replace("wav", "mp3"), asBytesArray);
But this is throwing me this exception:
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information: Access to the path 'G:\Song' is denied.
How can i solve this issue? Please help!
This is coming while I am debugging from Visual Studio
and i am not sure how to give administrative rights to the application which is being run as a debug
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.
This usually means that either there is a folder named "G:\Song", so you can't replace a directory with a file, or that your windows user account doesn't have permission to write to that drive.
Right-click on the drive and look at security permissions to be sure you have permission. Also, make sure the drive is not readonly, as in the case of a write-protected SD card or flash drive.
I had a similar issue and stumbled across this thread looking for an answer to another issue I am having.
But you issue sounds similar to one I had a few weeks ago, and the issue was that SYSTEM needed to also have Full Control over the folder.
May or may not be the issue, but mentioned incase it solves your or someone else's similar issue to what I experienced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With