Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Reading appSettings values from web.config file in asp.net

In this article, we are going to learn Reading Appsettings Values from web.config file in asp.net. In the previous article, I have explained, reading connectionString from web.config file in asp.net. This article is similar to previous one.

In web.config file:

Below is the structure of web.config file. In the appSettings, we can write application related settings like database connection strings, Document file location, Email setting,...etc.


xml version="1.0"?>
configuration>
appSettings>
add key="UploadFilePath" value="D:\Docs"/>
add key="FromMail" value="[email protected]"/>
add key="ToMail" value="[email protected]"/>
appSettings>
configuration>

And also, we need to add the System.Configuration dll to project. Below is step to add System.Configuration dll.

Step 1: Write click on references and click on add reference as shown below.

Step 2: Now the new window will open as show below. Go to Framework scroll down to System.Configuration and check to add and click on ok.

Step 3: Rebuild your application.

Step 4: Now, go to your Code-Behind file and include the below Namespace.


using System.Configuration;

Step 5: Below is the code snippet to read the appSettings values from web.config file using c#.


protected void Page_Load(object sender, EventArgs e)
{
string UploadFilePath = ConfigurationManager.AppSettings["UploadFilePath"].ToString();
string FromMail = ConfigurationManager.AppSettings["FromMail"].ToString();
string ToMail = ConfigurationManager.AppSettings["ToMail"].ToString();
}


This post first appeared on ASPArticles, please read the originial post: here

Share the post

Reading appSettings values from web.config file in asp.net

×

Subscribe to Asparticles

Get updates delivered right to your inbox!

Thank you for your subscription

×