I am trying to create a text file in C: using code (shown in picture) It says access is denied. Please help.
enter image description here
Thanks
-
You don't have access to the root folder.Jodrell– Jodrell2013年06月12日 08:34:38 +00:00Commented Jun 12, 2013 at 8:34
-
have you tried to investigate this issue yourself? there must be a lot of documentation regarding this kind of issue!default– default2013年06月12日 08:35:22 +00:00Commented Jun 12, 2013 at 8:35
3 Answers 3
The root of the C: drive is protected (On Windows Vista, 7, etc), so users cannot write to it unless the process is elevated.
Try right clicking on your compiled exe and then Run As Admin to test this theory.
The solution is to save your file somewhere else. This may help- Lemme Tell Ya Where to Stick It and Where Should I Store my Data and Configuration Files
Or you may want to create a temp file: How can I create a temp file with a specific extension with .NET? - you should have the relevant permissions to save this file but it cannot be guaranteed.
Comments
The user, who executes the program has no rights to create a file directly into the c:\ drive.
2 Comments
vsFilePath should be something like c:\log.txt not c: