{"id":477,"date":"2014-04-29T18:00:12","date_gmt":"2014-04-29T18:00:12","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=477"},"modified":"2015-08-20T11:31:45","modified_gmt":"2015-08-20T11:31:45","slug":"how-to-use-app-config-in-visual-studio-c-net","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/windows\/c\/how-to-use-app-config-in-visual-studio-c-net\/","title":{"rendered":"How to use App.config in Visual Studio C# .NET"},"content":{"rendered":"<p>Add reference to\u00a0<span class=\"lang:default decode:true  crayon-inline \">System.Configuration<\/span>\u00a0:<\/p>\n<p><a href=\"http:\/\/www.nikola-breznjak.com\/blog\/wp-content\/uploads\/2014\/04\/references.jpg\" rel=\"lightbox[477]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-478 size-full\" src=\"http:\/\/www.nikola-breznjak.com\/blog\/wp-content\/uploads\/2014\/04\/references.jpg\" alt=\"references\" width=\"919\" height=\"258\" srcset=\"https:\/\/nikola-breznjak.com\/blog\/wp-content\/uploads\/2014\/04\/references.jpg 919w, https:\/\/nikola-breznjak.com\/blog\/wp-content\/uploads\/2014\/04\/references-300x84.jpg 300w\" sizes=\"auto, (max-width: 919px) 100vw, 919px\" \/><\/a><\/p>\n<p>and include it using the using statement:<\/p>\n<pre class=\"lang:default decode:true\">using System.Configuration;<\/pre>\n<p>Edit\u00a0<span class=\"lang:default decode:true  crayon-inline \">App.config<\/span>\u00a0so that you add your settings in the <span class=\"lang:default decode:true  crayon-inline \">appSettings<\/span>\u00a0\u00a0node in an <span class=\"lang:default decode:true  crayon-inline \">add <\/span>\u00a0element with <span class=\"lang:default decode:true  crayon-inline \">key<\/span>\u00a0\u00a0and <span class=\"lang:default decode:true  crayon-inline \">value<\/span>\u00a0\u00a0parameters.<\/p>\n<pre class=\"lang:default decode:true\">&lt;?xml version=\"1.0\" encoding=\"utf-8\" ?&gt;\r\n&lt;configuration&gt;\r\n    &lt;startup&gt; \r\n        &lt;supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.5\" \/&gt;\r\n    &lt;\/startup&gt;\r\n\r\n    &lt;appSettings&gt;\r\n      &lt;add key=\"server\" value=\"localhost\" \/&gt;\r\n      &lt;add key=\"port\" value=\"5432\" \/&gt;\r\n      &lt;add key=\"username\" value=\"myusername\" \/&gt;\r\n      &lt;add key=\"password\" value=\"mypass\" \/&gt;\r\n      &lt;add key=\"database\" value=\"mydb\" \/&gt;\r\n    &lt;\/appSettings&gt;\r\n&lt;\/configuration&gt;<\/pre>\n<p>Now you can access your settings in\u00a0code like this:<\/p>\n<pre class=\"lang:default decode:true\">string server = ConfigurationManager.AppSettings[\"server\"].ToString();\r\nstring port = ConfigurationManager.AppSettings[\"port\"].ToString();\r\nstring username = ConfigurationManager.AppSettings[\"username\"].ToString();\r\nstring password = ConfigurationManager.AppSettings[\"password\"].ToString();\r\nstring database = ConfigurationManager.AppSettings[\"database\"].ToString();<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Add reference to\u00a0System.Configuration\u00a0: and include it using the using statement: using System.Configuration; Edit\u00a0App.config\u00a0so that you add your settings in the appSettings\u00a0\u00a0node in an add \u00a0element with key\u00a0\u00a0and value\u00a0\u00a0parameters.&hellip;<\/p>\n","protected":false},"author":1,"featured_media":479,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-477","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=477"}],"version-history":[{"count":2,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/477\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/477\/revisions\/481"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/479"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}