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

ConfgurationSettings Problem (Console App)

Status
Not open for further replies.

NoCoolHandle

Programmer
Apr 10, 2003
2,321
US
Hi..

I am playing with application settings. Specificly the ones you get to by selecting the properties of the project, going to the settings tab and adding a key.

When I do this, it creates a file using the following syntax

projectname.exe.config

In a winforms app I could read it using
Properties.Settings.Default.PropertyName

This doesn't exist in a console app. Instead you are supposed to use
ConfigurationSettings.AppSettings["PropertyName"]

However this returns null and checking the count of AppSettings returns 0

I have placed the config file in all the debug directorys

No luck getting the value.

any clues appreciated.

Rob

PS Inside of the file looks like.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="ConsoleReadSettings.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <ConsoleReadSettings.Properties.Settings>
            <setting name="RobSetting" serializeAs="String">
                <value>This is the test setting</value>
            </setting>
        </ConsoleReadSettings.Properties.Settings>
    </applicationSettings>
</configuration>
 
ConfigurationSettings.AppSettings["PropertyName"] reads properties like this
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="foo" value="bar" />
    </appSettings>
</configuration>
I think you need to design a custom config reader. there are examples of this on the web that are escaping me right now.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason,

thanks for your reply..

What I managed to find out..
GUI way of creating application/user settings creates a file with the name of the "[blue]projectName[/blue].EXE.Config" naming convention.

The values can be bound directly to properties of a form or textbox.. (much the same as resource files can work)

Using a winforms app you can access these name/value pairs via
Properties.Settings.Default.PropertyName
or in VB using the My Namespace..

However when you are using a CONSOLE app this doesn't work. You can extract the data if you use an xml file called
app.config.

The basic structure of the internal XML must is different.
Your XML is valid for the app.config file. The above post is valid for the GUI built file and winforms..

Frustrating that there are 2 ways of doing the same thing that are just not compatible.

THanks for looking!

ROb

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top