Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Read(Get) Appsettings Value from App.Config File in C#, VB.NET

Feb 26, 2015
Introduction:

Here I will explain how to read or get appsettings values from app.config file in
c#, vb.net. By using System.Configuration reference we can read or get appsettings values from app.config file in windows or console application in c#, vb.net.

Description:

In previous articles I explained export datagridview data to excel in windows application, create windows forms application setup file in c#, vb.net, delete windows service from system, create windows service in c#, vb.net and many more articles related to
asp.net using c#, vb.net. Now I will explain how to read or get appsettings values from app.config file in c#, vb.net.

To read appsettings values from app.config file first create new windows application and open your app.config file and add appsettings string like as shown below


<configuration>
<appSettings>
<add key="dbconnection" value="DataSource=Suresh;Initial Catalog=Praveendb; Integrated Security=true" />
</appSettings>
</configuration>

To read this appsettings value in our windows or console application we need to add System.Configuration reference for that follow below steps

Right click on your References folder à select Add Reference à select .NET tab à in that select System.Configuration à Click OK like as shown below



Once we add System.Configuration reference that our application reference folder will be like as shown below




















After completion of adding reference add following namespaces in codebehind

C# Code


using System.Configuration;

VB.NET Code


Imports System.Configuration;

After completion of adding namespaces you need to write the code like as shown below to get appsettings string from app.config file

C# Code


string strcon = ConfigurationManager.AppSettings["dbconnection"];

VB.NET Code


Dim strcon As String = ConfigurationManager. AppSettings ["dbconnection"];

I hope it helps you to read appsettings values from app.config file…. Happy coding…

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.