Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

app.config How to use them? 2

Status
Not open for further replies.

mheppler

Programmer
Feb 6, 2006
8
0
0
US
I have "SimpleClient.exe". I created an application configuration file "app.config"(see code below)to point SimpleClient to a new version of "Simple.dll" which is in the GAC. Should "app.config" be in the same directory or the root perhaps? When I run "SimpleClient.exe" MS wants to send an error report. Hope I didn't hose the GAC. Thanks.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Simple"
publicKeyToken="63498d099a31a153"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.1"
newVersion="1.0.0.2"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
 
typically, you would create a section under configuration called appSettings and add a key with a value.

<configuration>
<appSettings>
<add key="SimpleLocation" value="C:\Simple.dll" />
<appSettings>
</configuration>


Then from your code you would say

using System.Configuration;

public string GetSimpleLocation()
{
return ConfigurationSettings.AppSettings["SimpleLocation"].ToString();
}
 
app.config files work well enough, but they're read-only.

If you have a need to write to a configuration file, I like NIni, which is available on Sourceforge. It uses INI files instead of xml .config files, which are easier for many people to edit by hand.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top