[RESOLVED] R/W app.Config
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: [RESOLVED] R/W app.Config

  1. #1
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    962

    [RESOLVED] R/W app.Config

    I am able to read my parameters from my app.config file
    and did some googling and found that
    Code:
                             System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                              config.AppSettings.Settings["oldPlace"].Value = "3";
                              config.Save(ConfigurationSaveMode.Modified);
                              ConfigurationManager.RefreshSection("appSettings");
    but whaqt if OldPlace does not exist in the config and you need to add it rather than modifying it?

    How do you do this?

    Cheers
    Last edited by Saeed; June 2nd, 2009 at 07:30 PM.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: [RESOLVED] R/W app.Config

    Another one on my Ignore List
    Read here

  3. #3
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    962

    Re: [RESOLVED] R/W app.Config

    I posted a Question then i thought I figured out the answer to taht Q and marked it as resolved.

    What seems to be teh problem here ?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,289

    Re: [RESOLVED] R/W app.Config

    Quote Originally Posted by Saeed View Post
    I posted a Question then i thought I figured out the answer to taht Q and marked it as resolved.

    What seems to be teh problem here ?
    Marking it resolved doesn't help additional readers if you don't post the answer. It would be helpful if you would added the resolution when you mark the thread resolved.

  5. #5
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    962

    Re: [RESOLVED] R/W app.Config

    Code:
                    try
                    {
                        config.Save();
                    }
                    catch (ConfigurationErrorsException err)
                    {
                        MessageBox.Show("can not Save to Config\r\n" + err.ToString());
                    }
                    ConfigurationManager.RefreshSection("appSettings");
    ok . Fair enough i guess we have to share our solutions as well as the probelms and surely it did not require a fuse to be blown especially by a moderator who puts you on a ignore list because you are not psychic.
    Sometimes we all so busy about getting teh work done that we forget to do things properly that is to come back here and post teh solution.
    It is not a big deal and defintly does not require coming up with shameless and title and kindergarden Booing.

    We all come here and use this forum to ask a Q and hopefully get an answer.
    Maybe when the thread is marked as resolved it woudl be nice to pop up a text forcing the user to enter its final solution to the problem before closing it.

    I have been using this forum for years and this attitute from the codeguru was definitly not something I ever expected to see.

    A simpler " Please post your solution before marking it as resolved from now on " could have solved a lot of this. . That is what a moderator is supposed to do right?

    Saeed

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: [RESOLVED] R/W app.Config

    Saeed, this is the last thing I will say in this thread.
    Yes, I was being childish, fair enough. But, you were being selfish.
    In your own words we have to share our solutions as well as the probelms

    CG is a massive resource for a lot of newcomers especially. We are all here to learn and to help. By sharing our solutions makes it easier for the next person that encounters the very same problem. By not posting solutions, other members will also notice it, and regard you as a person that just takes and takes ( not saying this is the case - I don't know you ), then, more and more members will indeed ignore you. We both don't want that to happen. I believe every person on this forum ( and all the others ), is entitled to an answer to his / her question. Evrey person is entitled to learn.

    I work with 400 plus, students every day, and I see so many people not wanting to learn, this makes me immensely sad.

    I also believe that sharing doesn't cost anything, helping doesn't cost anything, fine, I suppose it's each person's perogative to help or not to help.

    Me being a moderator has nothing to do with it, I'd like to see myself as a member eith super powers . My main strengths are mostly in VB. I also like to learn new things, like C#. And the more I hang around in this forum, the more I learn.

    Yes, my behaviour as a Mod was probably childish, fine, but I have a job to do, and make sure people get answers. Yes, I have blown my fuse a bit, if you really want to see me blow my fuse, do some searches through some of my posts It's not something to brag about I admit.

    This all could've been avoided.

    Now, thank you for sharing your solution, and [i]Please post your solution before marking it as resolved from now on[i]

  7. #7
    Join Date
    May 2009
    Posts
    17

    Re: [RESOLVED] R/W app.Config

    I'm sorry for maybe a too easy question but I'm a beginner
    I'm trying to work with a config file, but vs doesn't recognize such
    a types like:
    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    and
    ConfigurationManager.RefreshSection("appSettings");
    I've written down using System.Configuration;
    what could be the problem?

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,289

    Re: [RESOLVED] R/W app.Config

    Quote Originally Posted by moshe5737 View Post
    I'm sorry for maybe a too easy question but I'm a beginner
    I'm trying to work with a config file, but vs doesn't recognize such
    a types like:
    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    and
    ConfigurationManager.RefreshSection("appSettings");
    I've written down using System.Configuration;
    what could be the problem?
    Moshe, since this thread has been resolved, you'll want to start a new thread for this question.

  9. #9
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: [RESOLVED] R/W app.Config

    If such is the situation then one can lock the RESOLVED threads as anyways you have to opne new threads for getting the problems resolved related to similar problems.

  10. #10
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: [RESOLVED] R/W app.Config

    but what if someone else would like to post another way of doing somethin? oh, and I want to add that I also don't like resolved threads without solution and/or without feedback.
    Last edited by memeloo; July 17th, 2009 at 02:49 AM.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  11. #11
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: [RESOLVED] R/W app.Config

    not this thread again

    Allow me to apologise ( publicly ) for my behaviour here. It wasn't my best moment. I just hop0e this thread never gets revived again, LOL!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center