none
What is the correct way to read from the config file? RRS feed

  • Question

  • We are doing it, I think, 4 different ways. What is the approach we are supposed to use.

    1. Some of our code is a commercial library that is used in web apps, Forms, apps, Silverlight, and more. So the method we use in it must work for all those cases.
    2. We are .NET 3.5 (because as a commercial library we have to run on .NET 2.0).

    ??? - thanks - dave


    Who will win The International Collegiate Programming Championships?

    Tuesday, June 19, 2012 7:18 PM

All replies

  • I used to do it many ways also, but now only use ConfigurationSection class to define my own configuration sections for the application configurations. My configurations might vary little bit between applications, but usually I can use big part of the once created configuration section classes and code in different apps.
    • Proposed as answer by Mythran Tuesday, June 19, 2012 8:45 PM
    • Unproposed as answer by DavidThi808 Sunday, June 24, 2012 10:27 PM
    • Proposed as answer by Mike FengModerator Monday, June 25, 2012 6:49 AM
    • Marked as answer by Mike FengModerator Sunday, July 8, 2012 8:56 AM
    • Unmarked as answer by DavidThi808 Wednesday, February 26, 2014 3:58 PM
    • Unproposed as answer by DavidThi808 Thursday, March 6, 2014 5:08 PM
    Tuesday, June 19, 2012 8:12 PM
  • Do you know if this is what Microsoft recommends as the best way to do this? We have most of our stuff this way too and it seems to work. But you never know when the "not recommended" ways suddenly will become a problem.

    thanks - dave


    Who will win The International Collegiate Programming Championships?

    Sunday, June 24, 2012 10:28 PM
  • David,

    Beside that your question has few to do with System Object the base class of .Net seems it a little bit strange to me.

    .Net is created to give more tastes, it is not MS Access where you can often choose only from one. 

    Microsoft would not have created so much tastes as there was only one correct solution, then they had created one, it would have been much cheaper for them.

    Be aware that you are talking about apples and pears, a config in a Asp.Net application controls the settings for the application (on the Server), not for one client. A config.sys in a Windows Forms application controls the settings for one user. However, I can think about many other kind of solutions.



    Success
    Cor

    Monday, June 25, 2012 5:35 AM
  • Do you know if this is what Microsoft recommends as the best way to do this? We have most of our stuff this way too and it seems to work. But you never know when the "not recommended" ways suddenly will become a problem.

    thanks - dave


    Who will win The International Collegiate Programming Championships?

    I don't think that is the "best way Microsoft recommends it", if there is one I'd like to know that too. That was just my advice, if configurations are in database then this is clearly not the best way to do it.

    Cor is right, you need to give more context to your question to get the right answer and after that it's still possible that there is no one right and recommended way to do it.

    Monday, June 25, 2012 8:23 AM
  • Hi;

    Asking again, what is the official Microsoft recommended way to place values in the app.exe.config file? And if the official answer is we have 4 different ways for various needs, what is the guidance for when each of those approaches works best?

    Our library is built under .net 3.5 and we have customers using everything from .NET 2.0 to .NET 4.5 using it.

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Tuesday, February 11, 2014 9:42 PM
  • I unmarked this as the answer because it does not provide the recommended use cases by Microsoft, just a single individuals opinion. I want to know what the official best practices are.

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Wednesday, February 26, 2014 3:58 PM
  • Asking again - what's Microsoft's recommended best practices for this.

    thanks- dave


    Who will win The Windward International Collegiate Programming Championships?

    Thursday, March 6, 2014 5:09 PM