{"id":450,"date":"2010-10-01T02:31:21","date_gmt":"2010-10-01T02:31:21","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=450"},"modified":"2010-10-01T02:31:21","modified_gmt":"2010-10-01T02:31:21","slug":"winform-app-config%e8%af%bb%e5%86%99","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2010\/10\/01\/winform-app-config%e8%af%bb%e5%86%99\/","title":{"rendered":"WinForm app.config\u8bfb\u5199"},"content":{"rendered":"<pre lang=\"csharp\">\r\npublic static string GetValue(string AppKey)\r\n        {\r\n            try\r\n            {\r\n                string AppKeyValue;\r\n                AppKeyValue = System.Configuration.ConfigurationSettings.AppSettings.Get(AppKey);\r\n                return AppKeyValue;\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                throw ex;\r\n            }\r\n        }\r\n\r\n        public static void SetValue(string AppKey, string AppValue)\r\n        {\r\n            \/\/System.Configuration.ConfigurationSettings.AppSettings.Set(AppKey,AppValue);\r\n            XmlDocument xDoc = new XmlDocument();\r\n            xDoc.Load(System.Windows.Forms.Application.ExecutablePath + \".config\");\r\n\r\n            XmlNode xNode;\r\n            XmlElement xElem1;\r\n            XmlElement xElem2;\r\n            xNode = xDoc.SelectSingleNode(\"\/\/appSettings\");\r\n\r\n            xElem1 = (XmlElement)xNode.SelectSingleNode(\"\/\/add[@key='\" + AppKey + \"']\");\r\n            if (xElem1 != null) xElem1.SetAttribute(\"value\", AppValue);\r\n            else\r\n            {\r\n                xElem2 = xDoc.CreateElement(\"add\");\r\n                xElem2.SetAttribute(\"key\", AppKey);\r\n                xElem2.SetAttribute(\"value\", AppValue);\r\n                xNode.AppendChild(xElem2);\r\n            }\r\n            xDoc.Save(System.Windows.Forms.Application.ExecutablePath + \".config\");\r\n        }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>public static string GetValue(string AppKey) { try { st [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-450","post","type-post","status-publish","format-standard","hentry","category-aspdotnet"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=450"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/450\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}