c# - update app.config file programatically with ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); -


Update the app .config file with the program

Configuration Configuration = Configuration Manager. Openexe configuration (configuration subsystem level none);

This is my XML

  & lt; Configuration & gt; & Lt; ConfigSections & gt; & Lt; Section name = "nhibernate settings" type = "ProjectBase.Data.OpenSessionInViewSection, ProjectBase.Data" /> & Lt; / ConfigSections & gt; & Lt; AppSettings & gt; & Lt; Add key = "NHibernateConfigPath" value = "D: \ PROJEKTI \ crawler \ WebCrawlerSuite \ ViaMura.Web \ NHibernate.config" /> & Lt ;! - & lt; Add key = "NHibernateConfigPath" value = "C: \ _ZAGON \ ViaMura \ CurrencyApp \ at \ NHibernate.config" /> - & gt; & Lt; Add Key = "Client SettingsToppedRepair Service" Value "" = "" /> & Lt; / AppSettings & gt; & Lt; ConnectionStrings & gt; & Lt; Add name = "connectionString" connectionString = "Integrated Security = SSPI; Security Info = False, Initial Catalog = Viamura_at; Data Source =. \ SQL2008" providerName = "System.Data.SqlClient" / & gt; & Lt ;! - & lt; Add name = "connectionString" connectionString = "server = 193.37.152.24 \ SQL2008; user id = dbusar; password = lualah8991; database = viamura_at" providerName = "System.Data.SqlClient" / & gt; - - & gt; & Lt; / ConnectionStrings & gt; & Lt; NhibernateSettings & gt; & Lt ;! - List of every session factory which will be required; Transaction management and closing sessions will be managed with the open-session-in-view module - & gt; & Lt; SessionFactories & gt; & Lt; Explicit Factory /> & Lt; SessionFactory name = "Web crawler factor" factory config way = "D: \ projector \ crawler \ webcrawler site \ Viaimura web \ NHibernate.config" heresensection = "true" /> & Lt ;! - & lt; SessionFactory name = "WebCrawler Factory" factory config = "C: \ _Zagan \ Vayamura \ currency app \ NHibernate.config" Transaction = "true" /> and & gt; & Lt; / SessionFactories & gt; & Lt; / NhibernateSettings & gt;   

How can I edit WebRrawlerFactory programmatically? I

Configuration Configuration Configuration Configuration Manager. Openexe configuration (configuration standard level. Non);

You can use the following code:

  Private Zero UpdateConfig (string key, string value, string fileName) {var configFile = ConfigManager.OpenExeConfiguration (fileName); Configfile.AppSettings.Settings [key] .Value = value; ConfigFile.Save (); }   

Where: file name is the full path + application name (c: \ project \ application.exe)

In your case, change the app settings by section Do:

  configfile.Sections ["nhibernateSettings"]    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -