I have read a similar post, but i just cant figure out the problem.
I have changed the windows permissions and changed routes.
When i try to save a file it throws me the exception:
Access to the path **** denied.
string route="D:\\"; FileStream fs = new FileStream(route, FileMode.Create); <--here is the problem StreamWriter write = new StreamWriter(fs); patient person = new patient(); patient.name = textBox1.Text; patient.name2 = textBox2.Text;
You may see “Access to the path is denied” error if the application is not able access to a path that is trying to read or write. This will show up as 401 Unauthorized error in IIS logs.
Right-click Visual Studio <VersionNumber>, select Change, and then select Repair to initiate the repair process.
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.
Start a Command Prompt as Administrator by right-clicking on the "Command Prompt" icon in the Windows Start Menu and choose "Run as administrator". Click Continue if you are presented with a confirmation popup message box. In the new command prompt, enter "net user administrator /active:yes".
You are trying to create a FileStream object for a directory (folder). Specify a file name (e.g. @"D:\test.txt") and the error will go away.
By the way, I would suggest that you use the StreamWriter constructor that takes an Encoding as its second parameter, because otherwise you might be in for an unpleasant surprise when trying to read the saved file later (using StreamReader).
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