none
Configuration Settings in c sharp RRS feed

  • Question

  • Hi All,

    I m using c sharp and I have app.config file as follows,

    <?

     

    xml version="1.0" encoding="utf-8"

    ?>

    <

     

    configuration

    >

    <

     

    appSettings

    >

    <

     

    add key ="ProductName" value="QDMS"

    />

    <

     

    add key ="Version" value="5.27"

    />

    <

     

    add key ="ErrorLogFile" value ="QDMSErrorLog.txt"

    />

    <

     

    add key ="FilePath" value ="C:\\"

    />

    </

     

    appSettings

    >

    </

     

    configuration>

    Now I want to get the values (Eg. ProductName, "QDMS") from the users for each key.Is there any way to achieve this. I.e. if I ask user to Enter his product name and pass that value to the app.config value?

     

     

     
    Friday, April 8, 2011 8:28 AM

Answers

All replies

  • You can get assembly's config object following below code:

          string configFile = Path.ChangeExtension(System.Reflection.Assembly.GetCallingAssembly().Location, ".config");
          System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(configFile);
    
    Friday, April 8, 2011 9:09 AM
  • You can use OpenExeConfiguration method to get System.Configuration.Configuration object for an app config file.

    Using this you can read/write data from/to the underlying config file.

    See the Config class below

    http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx?ppud=4


    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    • Marked as answer by Paul Zhou Wednesday, April 13, 2011 2:06 AM
    Friday, April 8, 2011 10:22 AM
  • hi Prakash,

    This is helpful for me . thanks.

    • Marked as answer by Creative_Pro Tuesday, April 12, 2011 12:18 PM
    Tuesday, April 12, 2011 12:15 PM