Click here to Skip to main content
15,885,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi How to create a file inside Program Files or Windows folder of C drive when I am trying to create a file in windows form application it will through an exception


"An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

Additional information: Access to the path 'C:\Program Files\test.xml' is denied."


Is there any way to create file inside this 2 folder
please suggest me how would I do.

Thanks
Prafulla
Posted
Updated 7-Sep-12 1:44am
v2
Comments
[no name] 7-Sep-12 7:40am    
run as administrator

You need to run your application with Administrator Privilege.

Change following settings into your application Manifest.
HTML
<requestedexecutionlevel level="requireAdministrator" uiaccess="false" />
 
Share this answer
 
Comments
Prafulla Sahu 7-Sep-12 7:45am    
Thanks Malli for your reply but sorry Malli I need for windows application
Malli_S 7-Sep-12 7:54am    
That IS for windows application. If you don't have manifest file you can add one and update the above specified setting.
Eddy Vluggen 7-Sep-12 8:03am    
Although your solution works, I have to disagree; it's a silly request, and we don't write in those locations. At all. Ever.

The only reason to request something like this, is when someone wants to HIDE his app from the user - your typical trojan-writer.
Malli_S 7-Sep-12 8:37am    
I agree with you. :)
Prafulla Sahu 11-Sep-12 4:33am    
Thanks mali and Eddy for your reply but I want to hide my app.good guess Eddy and malli
You should store your data elsewhere. It is "not done" to write in the Program Files folder, nor the Windows-folder. These are special system-folders, and your app should not touch them.
 
Share this answer
 

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