Click here to Skip to main content
13,295,953 members (52,449 online)
Rate this:
Please Sign up or sign in to vote.
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.

Posted 7-Sep-12 2:36am
Updated 7-Sep-12 2:44am
Wes Aday 7-Sep-12 7:40am
run as administrator
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to run your application with Administrator Privilege.

Change following settings into your application Manifest.
<requestedexecutionlevel level="requireAdministrator" uiaccess="false" />
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100