a developer's notes – a semi-technical web development BLOG

January 25, 2012

Reading values from a config file

Filed under: ASP.NET,C# — Duy Nguyen @ 9:00 am
Tags: , , , , , , , , , ,

From the c# code behind:

 private string myConfigMapping = ConfigurationManager.AppSettings["ComputerName"];

Add your config file. (app.config or web.config)

<?xml version="1.0"?>
<configuration>
	<connectionStrings>
		<add name="connectionString" connectionString="Data Source=(local);Initial Catalog=AdventureWorksLT2008R2;Integrated Security=SSPI"/>
	</connectionStrings>
	<appSettings>
		<add key="ComputerName" value="John-PC"/> //Add your key and value here!
	</appSettings>
	<startup>
		<supportedRuntime version="v2.0.50727"/>
	</startup>	
</configuration>
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: