Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to create a text file in C: using code. It says access is denied.
Please help.

Dim vrCommand As String = "This is my test file data"

        System.IO.File.AppendAllText(vrFilePath, vrCommand & vbCrLf)



It return error:
Access to the path 'C:\' is denied.
Posted

Yes, you need administrator privileges to write to the OS drive root (since windows vista)

Good luck!
 
Share this answer
 
Comments
Furqan Sehgal 12-Jun-13 4:22am    
To the root only? I tried C:\MyTestFolder but it gives says 'Access is denied'
Please note I have already created MyTestFolder
E.F. Nijboer 12-Jun-13 6:33am    
Well, in the years windows has progressed to be more conservative about letting programs access all kind of files in whatever directory it would like. You need to understand that you are a user with a folder dedicated for your files in the folder Users ("Documents and Settings" before microsoft realized they are still bound by their own stupidity of maximum path lengths etc...). An application runs in the context of a user, but changes outside of the users own folder could impact all users and is therefor privileged.
Surendra Adhikari SA 12-Jun-13 4:33am    
try creating ,modifying a text file in that folder (C:\MyTestFolder ). This error is usually generated due to O.S.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900