Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello Friends,

I need to write to a file which exists in C:\Program files (X86) in vista. I am using C# to write to that file programatically, but I am not able to do that. Please suggest a solution.

Thanks,
Jagjot
Posted

You shouldn't be writing anything at all under Program Files. Every folder under that location is ReadOnly to normal Users. You have to pick a more appropriate location to write the data you want.

If you're looking at sharing data between users of the application on the same machine, then you have to write it to something under the path returned by System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData).
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 5-Apr-11 13:49pm    
Or System.Environment.SpecialFolder.LocalApplicationData or the like.
Correct Answer, my 5.
--SA
You need to probably change some settings in the User Account Control.
 
Share this answer
 
Comments
Kim Togo 5-Apr-11 9:04am    
Bad idea. UAC is there for a reason. Disable it, is not the way to go.
Toli Cuturicu 5-Apr-11 13:12pm    
Voted 5 to counter an idiot's 1.
You will probably have to run your application as an administrator and/or programmatically demand FileIOPermission that lets you write there.

Have a look at these:

http://stackoverflow.com/questions/2432329/how-do-i-deploy-applications-in-run-as-administrator-mode[^]

http://msdn.microsoft.com/en-us/library/system.security.permissions.fileiopermission.aspx[^]

Good luck!
 
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