I’m trying to write a blank text file which is included within my installer but i’m getting the following error;
System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\Hex Technologies\wamplocation.txt' is denied.
It seems to be the permissions of the file once it’s installed through my installer, but how can I set the file to be fully modifiable once the file installed?! Can this be done through C#?!
EDITTED;
wamp_url = openFileDialog1.FileName.ToString();
String EnviromentPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
StreamWriter outfile = new StreamWriter(EnviromentPath + @"\Hex Technologies\wamplocation.txt");
outfile.Write(wamp_url);
outfile.Close();
You should not store your modifyable data files in the Program Files path. Use
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)orEnvironment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)The Program Files\… path is protected against modification by normal users on Win7+. It would be a bad idea to try to circumvent that protection.