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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using App.Config

Status
Not open for further replies.

prrm333

Programmer
Apr 14, 2003
97
US
I am trying to use the following code to read a file name from the App.Config tab in the express version:

public string GetDataFile()
{
string sFile = ConfigurationSettings.AppSettings["sFile"];
MessageBox.Show(sFile);
return sFile;
}

When I output the string in the message box it returns blank. What am I doing wrong?

Thanks.
 
the key is case sensative; so sFile is different from SFile which is different than Sfile which is... you get the idea.

this would be the first thing to check.

post the appsettings node of the app.config this may also give some insight into the problem.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I checked and sFile is all the same.

The appsettings node of the app.config is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="sFile" value="data.xml" />
</appSettings>
</configuration>
 
i'm stumped, looks good from here?
with assembly projects you need to reference System.Configuration, but if this isn't included it should throw a exception at compile time.

try removing [tt]encoding="utf-8"[/tt]. it shouldn't matter, but it's the only difference I can see.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi,

ConfigurationSettings.AppSettings is obsolete. I suggest you use ConfigurationManager.AppSettings["Keyname"].

Ryan
 
I'll look into this but I actually have it working using an XML configuration file and reading in what data I need at that time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top