Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to determine the setting problem and method of VS2005 configuration

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to determine the configuration of VS2005 settings and methods, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

For example, DateTime userDateTime1 = Properties.Settings.Default.userDateTime1; is a lot more convenient. But have you found that after saving the settings with Properties.Settings.Default.Save (), why the Application-scoped settings are not saved successfully, and why the changes in User-scoped settings are not reflected in the app.config file?

1. Make application settings in VS 2005 to open project properties »settings, as shown in the following figure:

Enter the name, select the type and range, and save the value to complete the setting. Type: various data types such as int,string,DateTime; range: Application range settings are valid for all users

The User scope setting is valid for the current user (the current Windows logged-in user), and each user can have different values for the same setting and do not affect each other.

two。 Read configuration file (read application settings)

Whether it is the Application range setting or the User range setting, the reading method is the same.

Read setting this.appSetting1TextBox.Text = Properties.Settings.Default.appSetting1; this.userSetting1TextBox.Text = Properties.Settings.Default.userSetting1

3. Save User scope configuration file (save User scope application settings)

Save User range settings Properties.Settings.Default.userSetting1 = this.userSetting1TextBox.Text; Properties.Settings.Default.Save ()

The VS2005 configuration file is not saved in the application folder, but here: X:\ Documents and Settings\ Windows login user\ Local Settings\ Application Data.

4. Save the Application scope configuration file (save the Application scope application settings) Save the Application scope configuration file is not as simple as saving the User scope configuration file, just Properties.Settings.Default.Save () is not possible. Because the Application scope setting is "read-only" at run time. The method used here is to use XmlDocument to save the config file directly, and then set it in Reload.

Save Applicationi range settings string configFileName = Application.ExecutablePath + ".config"; System.Xml.XmlDocument doc = new System.Xml.XmlDocument (); doc.Load (configFileName); string configString = @ "configuration/applicationSettings/SetConfig.Properties.Settings/setting [@ name='appSetting1'] / value"; System.Xml.XmlNode configNode = doc.SelectSingleNode (configString); if (configNode! = null) {configNode.InnerText = this.appSetting1TextBox.Text; doc.Save (configFileName) / / refresh the application settings so that the value of * * can be read the next time it is read. }

By the way: use Properties.Settings.Default.Reset () to restore the default values of the VS2005 configuration settings (from app.config).

The above is all the contents of the article "how to determine the setting problem and method of VS2005 configuration". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report