Is it possible to load app.config file from arbitrary path? RRS feed

  • Question

  • I have created the App.config file:

    <?xml version="1.0" encoding="utf-8" ?>   



    <add name="InetConnectionString" connectionString="Data Source=mtms\;Initial Catalog=inet;Persist Security Info=True;User ID=aaa;Password=1;Pooling=False"/>    



    This config file path is H:\tmp\App.config

    I run the console app from C:\Users\User\Documents\visual studio 2012\Projects\ConfigEncryptionTest
    Here is the code in Console app:

    static void Main(string[] args)        {           

    ExeConfigurationFileMap map = new ExeConfigurationFileMap();           

    map.ExeConfigFilename = @"H:\tmp\App.config";                     

    Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);       


    I don't know why, but the config object does not contain connection string named InetConnectionString. Instead, it contains only "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"

    Tuesday, August 7, 2012 7:10 AM


All replies