Loading application settings from a file.

Posted on 2011-10-29
Last Modified: 2012-05-12
I am trying to load a config file from my server to set the application settings but when my program launches it still has the default settings in it.  The settings are being loaded but it appears they are being overwrote by the defaults after that.  When is the application settings loaded by the file?  I have tried placing a timer to load my file after the program finishes loading.  I tried placing my load config on my login form(the timer opened it after a 15 second delay).  Neither option made any effect.

Question by:mmosoul
    LVL 40

    Expert Comment

    by:Jacques Bourgeois (James Burger)
    Unless you create your own class to read it, the .config file must be located in the application folder, and it is read before your first line of code executes.

    If you need to get it from the server each time the application start, the only way I see would be to have a launcher application.

    You launch the launcher.
    It copies the .config file from the server to the local directory.
    It then launch the application.
    LVL 2

    Expert Comment

    After you  load the config ,you assign  the valus in the config  to program's variables. Then it can run rightly  according to those variables.
    Since you say the settings have been loaded , then I think the wrong link is the assign process.You try to  debug it. come on!

    Accepted Solution

    I have buttons to change the settings anywhere through my program, they all change the settings and it saves.  Why does it have to be in the application folder?  It's reading a text file and changing the values.  I want to read this file and have it change the values after the program loads so I can make changes and have them effects all clients when they load.  I can add a button to call this function and the values change.  This function is called long after the first line of the program so if the client side file is loaded before the first line of the program then it makes absolutely no sense as to why it's not working.
    LVL 40

    Expert Comment

    by:Jacques Bourgeois (James Burger)
    My.Settings, as any other feature in the My environment, has been designed to simplify things for VB developers. It has been designed mostly for amateurs. A great time saving, but that does not offer you complete control over things. My.Settings has thus been designed to work with a config file located in the application directory, because this is what most programmers do.

    If you want to customize the way you handle the settings, you will have to either devise your own system, or modify the standard behaviour by writing your own code around the classes that you will find in the System.Configuration namespace.
    LVL 8

    Expert Comment

    Another point to note: would it be possible that you are setting the default settings in the code somewhere... as in after the settings have been read in?

    Author Closing Comment

    I can find no reason for anything I tried to not work.  I can change the settings by clicking a button after my program is loaded, I should be able to do the same thing in the program.  I even had my program click the button that I click with the mouse but....after exhausting all resources I have abandoned the idea.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now