简体   繁体   中英

writing User configuration back to app.config in .net application

I have a windows application. I am writing all user specific settings into user.config.

Now in a new scenario, whatever changes one user does it should reflect to all the users.

For that purpose I thought of writing the settings into app.config through

Properties.Settings.Default.p1 = value;
Properties.Settings.Default.Save();

And every user read the updated default value after

Reset();

But what ever I do…it still writes to user.config not to app.config

From my experience, the Settings class cannot be used to modify default setting values for all users. In this situation, I modify the app.config directly using the classes in the System.Xml namespace. It is not ideal, but I have not found any other way to do it.

There are a couple things to keep in mind when modifying your app.config file:

  • If your program is installed in the Program Files folder, you may need to run your application as an administrator in order to save changes to the file. It will depend on how your security is configured.
  • If you change the namespace of your Settings class, it will change the structure of your app.config file, so you would need to update your code to account for the new XML structure.

See this MSDN article for more information about application and user scoped settings: http://msdn.microsoft.com/en-us/library/8eyb2ct1%28v=vs.110%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM