Does the config file create and delete temporary files whenever we make changes to it?

I am developing a desktop application and I am using a config file to store custom settings for the application. Please find below code to save changes to config file:

Configuration configFile = ConfigurationManager.OpenExeConfiguration(exePath);
                if (configFile.AppSettings.Settings[key] != null)
                {
                    configFile.AppSettings.Settings.Remove(key);

                }
                if (param)
                {
                    configFile.AppSettings.Settings.Add(key, value);
                }

                    configFile.Save(ConfigurationSaveMode.Modified);

      

I store this config file in the following path:

C: \ Users \ username \ AppData \ Local \ some folder \ some folder \ some folder

The problem is that on some machine the user has limited rights. And whenever the application tries to save the settings in the config file, it throws an exception:

An attempt was made to perform an unauthorized operation.

It seems from the machine logs that the config library is creating and deleting a temporary file during a save operation. So how do I avoid this exception?

+3


source to share





All Articles