C # Read the values in the configuration file,

Source: Internet
Author: User

C # Read the values in the configuration file,

Using System; using System. windows. forms; using System. xml; namespace BlackBoxForms. app_Code {// <summary> /// set the configuration file // </summary> public class SetAppConfig {public static string AppConfig () {return System. IO. path. combine (Application. startupPath, "BlackBoxForms.exe. config ");} /// <summary> /// obtain the value based on WCF /// </summary> /// <param name = "appKey"> key </param> // <returns> value </returns> public static String GetAddress (string appKey) {try {XmlDocument xmlDoc = new XmlDocument (); xmlDoc. load (AppConfig (); XmlNode xNode = xmlDoc. selectSingleNode ("// system. serviceModel // client "); XmlElement xElem = (XmlElement) xNode. selectSingleNode ("// endpoint [@ name = '" + appKey + "']"); if (xElem! = Null) return xElem. getAttribute ("address"); else return "" ;}catch (Exception) {return "";}} /// <summary> /// set the WCF Service /// </summary> /// <param name = "appKey"> key </param> /// <param name = "appValue"> value </param> // <returns> the result is true: success, false: Failed </returns> public static bool SetValueByName (string appKey, string appValue) {try {XmlDocument xmlDoc = new XmlDocument (); xmlDoc. load (AppConfig ()); XmlNode xNode = xmlDoc. selectSingleNode ("// system. serviceModel // client "); XmlElement xElem1 = (XmlElement) xNode. selectSingleNode ("// endpoint [@ name = '" + appKey + "']"); if (xElem1! = Null) {xElem1.SetAttribute ("address", appValue);} else {XmlElement xElem2 = xmlDoc. createElement ("endpoint"); xElem2.SetAttribute ("name", appKey); xElem2.SetAttribute ("address", appValue); xNode. appendChild (xElem2);} xmlDoc. save (AppConfig (); return true;} catch (Exception) {return false ;}} /// <summary> /// obtain the value based on the key /// </summary> /// <param name = "appKey"> key </param> /// <returns> va Lue </returns> public static string GetValue (string appKey) {try {XmlDocument xmlDoc = new XmlDocument (); xmlDoc. load (AppConfig (); XmlNode xNode = xmlDoc. selectSingleNode ("// appSettings"); XmlElement xElem = (XmlElement) xNode. selectSingleNode ("// add [@ key = '" + appKey + "']"); if (xElem! = Null) return xElem. getAttribute ("value"); else return "" ;}catch (Exception) {return "";}} /// <summary> /// set the value based on the key /// </summary> /// <param name = "appKey"> key </param> /// <param name = "appValue"> value </param> // <returns> the result is true: success, false: Failed </returns> public static bool SetValueByKey (string appKey, string appValue) {try {XmlDocument xmlDoc = new XmlDocument (); xmlDoc. load (AppConfig () ); XmlNode xNode = xmlDoc. selectSingleNode ("// appSettings"); XmlElement xElem1 = (XmlElement) xNode. selectSingleNode ("// add [@ key = '" + appKey + "']"); if (xElem1! = Null) {xElem1.SetAttribute ("value", appValue);} else {XmlElement xElem2 = xmlDoc. createElement ("add"); xElem2.SetAttribute ("key", appKey); xElem2.SetAttribute ("value", appValue); xNode. appendChild (xElem2);} xmlDoc. save (AppConfig (); return true;} catch (Exception) {return false ;}}}}

 


C :\

Yes

Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)

Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>

C :\

Yes

Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)

Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.