I have a text file in Program Files. I cannot write it from a C# application while running in non-admin mode.
I am using this snippet
TextReader read = new StreamReader("C:\Program Files\......\link");
It is throwing an error that the access to the file is denied, however I can read it!
Thanks
Access to a file can be different for reading and writing. As a non-admin, it’s normal to be able to read files in Program Files, but not be able to write them.
If the file is a setting for the current user, you should put it in a folder under the AppData folder. You can find the AppData folder’s location by calling
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))If the file is a setting for all users on the computer, use
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData))See http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx for a list of other possible special folder locations.