{"id":1138,"date":"2010-09-19T20:48:10","date_gmt":"2010-09-19T15:18:10","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1138"},"modified":"2010-09-19T20:48:10","modified_gmt":"2010-09-19T15:18:10","slug":"how-to-read-value-from-configuration-file-app-config-or-web-config","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/how-to-read-value-from-configuration-file-app-config-or-web-config\/","title":{"rendered":"How to read value from Configuration file &#8211; ( app.config or web.config )"},"content":{"rendered":"<p>One of the best practice used in .NET application is to store the constants like Database connection in <strong>app.config <\/strong>in case of dll or standalone application or <strong>web.config <\/strong>in case of websites.<\/p>\n<p>To achieve this, we have to follow below steps:<\/p>\n<figure id=\"attachment_1140\" aria-describedby=\"caption-attachment-1140\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/09\/System.Configuration.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1140\" title=\"add reference of System.Configuration in .NET\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/09\/System.Configuration-300x250.jpg?resize=300%2C250&#038;ssl=1\" alt=\"add reference of System.Configuration in .NET\" width=\"300\" height=\"250\" \/><\/a><figcaption id=\"caption-attachment-1140\" class=\"wp-caption-text\">add reference of System.Configuration in .NET<\/figcaption><\/figure>\n<p>Lets consider below code in <strong>web.config<\/strong><\/p>\n<p><span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;\"><!--more--><\/span><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;appSettings&gt;\n    &lt;add key=&quot;ConnectionString&quot; value=&quot;Data Source=SHIVASOFTSHIVASOFT;Initial Catalog=testDb;\nIntegrated Security=True&quot;\/&gt;\n  &lt;\/appSettings&gt;\n<\/pre>\n<p>So, to read the key <strong>ConnectionString<\/strong>, we have to use below code in C#.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nString dbConnection = System.Configuration.ConfigurationManager.\nAppSettings&#x5B;&quot;ConnectionString&quot;];\n<\/pre>\n<p>Where &#8220;<strong><span style=\"color: #993300;\">ConnectionString<\/span><\/strong>&#8221; is the key present in <strong>web.config <\/strong>or <strong>app.config.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to read value from Configuration file &#8211;  app.config or web.config in C# application or web application<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[21,22],"tags":[43],"class_list":["post-1138","post","type-post","status-publish","format-standard","hentry","category-net","category-csharp","tag-asp-net"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":258,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/tracing-asp-net-website\/","url_meta":{"origin":1138,"position":0},"title":"Tracing ASP.NET Website","author":"Jitendra","date":"June 28, 2010","format":false,"excerpt":"Demonstrates that how to Trace ASP.NET web applications","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"ASP.NET Tracing Output","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/Tracing-FirstPage1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":125,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/cannot-access-a-closed-file-fileupload-in-asp-net\/","url_meta":{"origin":1138,"position":1},"title":"cannot access a closed file &#8211; FileUpload in ASP.NET","author":"Jitendra","date":"May 13, 2010","format":false,"excerpt":"This was very\u00a0interesting\u00a0error, i got during development of file upload control in ASP.NET. On my local system, every thing was just fine. but when i deployed my application on development server, my control was able to upload only small size files. whenever i tried to upload large size file i\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":132,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/upload-files-in-asp-net-at-production-server\/","url_meta":{"origin":1138,"position":2},"title":"Upload Files in ASP.NET at Production server","author":"Jitendra","date":"May 13, 2010","format":false,"excerpt":"In this article, i am going to demonstrate that how to upload the file in ASP.NET production server. Most of the case, a developer created a code to upload the file and test it on his local machine. program runs smoothly, but as he\u00a0forward\u00a0the same code on production. He\u00a0stuck\u00a0in the\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/WebShare-Folder.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1029,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/logging-made-easy-in-net-log-4-net\/","url_meta":{"origin":1138,"position":3},"title":"Logging made easy in .NET &#8211; log 4 net","author":"Jitendra","date":"September 30, 2010","format":false,"excerpt":"How to use the log 4 net in .Net application. Example, demonstration and sourcecode","rel":"","context":"In &quot;c#&quot;","block_context":{"text":"c#","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/csharp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2299,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/tutorial-read-and-export-excel-file-in-asp-net-using-c\/","url_meta":{"origin":1138,"position":4},"title":"Tutorial &#8211; Read and export excel file in ASP.Net  using C#","author":"Jitendra","date":"July 29, 2011","format":false,"excerpt":"Tutorial - Read and export excel file in ASP.Net using C#","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Read And Export Excel in ASP.Net","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/07\/Read-And-Export-Excel-in-ASP.Net_.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1155,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/set-session-timeout-in-iis-internet-information-services\/","url_meta":{"origin":1138,"position":5},"title":"Set Session Timeout in IIS (Internet Information Services)","author":"Jitendra","date":"September 28, 2010","format":false,"excerpt":"Step by step description to set the Session.Timeout in IIS(Internet Information Services) Server for ASP.NET","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"IIS Website Properties","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/09\/IIS-Website-Properties-300x297.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1138"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1138\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}