ApplicationSettings in 2.0

VBAHole22

Contributor
Joined
Oct 21, 2003
Messages
432
Location
VA
Maybe I am missing something really obvious but I am at a loss on this.
1.Went into my 2.0 win app and got to the properties page (vs2005).
2.Added a few string settings on the settings tab (application scope).
3. this results in the following xml bit in the app.config file (which i spawned earlier):
Code:
   <applicationSettings>
        <Myapp.Properties.Settings>
            <setting name="LogOutputFilePath" serializeAs="String">
                <value>C:\\Temp\\ErrorLog\\</value>
            </setting>
        </Myapp.Properties.Settings>
    </applicationSettings>

4.In code I want to pull this value out using:
Code:
string path = ConfigurationManager.AppSettings.Get("LogOutputFilePath");


The string is always null. i can never get the value. I have a ref to System.Configuration and I have the using. What am I missing here?
 
Thank you, thank you, thank you.

I'm very happy to have a solution.

That said.
Holy Cr*p why does ms make this so difficult?
I googled this for like an hour and didn't come up with any ideas.
Even msdn was refering to appSettings. Unbelievable.
 
Perhaps I spoke too soon.

I can use this method to access settings in my win app - no worries.
However I also have a class library in this solution with business logic. This project cannot see the Properties namespace so the method doesn't work.
When I built stuff like this in 1.0 I was able to use a single app.config and all projects could see it.

I don't want to have to put a properties/app.config page in my business logic class library.
 
Have you tried to create your properties as part of the ClassLibrary project? If not give it a try, The Properties.Settings etc. for a classlibrary is saved to / read from the calling application's config file.

It makes it just as simple to use with dlls.
 
Back
Top