Tuesday, February 11, 2014

Update app.config in c# programing


Question :

update app.config file programatically with
Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None);

this is my xml

<configuration> <configSections> <section name="nhibernateSettings" type="ProjectBase.Data.OpenSessionIn ViewSection, ProjectBase.Data" /> </configSections> <appSettings> <add key="NHibernateConfigPath" value="D:\PROJEKTI\crawler\WebCrawle rSuite\ViaMura.Web\NHibernate.config " /> <!--<add key="NHibernateConfigPath" value="C:\_ZAGON\ViaMura\CurrencyApp \at\NHibernate.config" />--> <add key="ClientSettingsProvider.ServiceU ri" value="" /> </appSettings> <connectionStrings> <add name="connectionString" connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Viamura_at;Data Source=.\SQL2008" providerName="System.Data.SqlClient" /> <!--<add name="connectionString" connectionString="server=193.37.152. 24\SQL2008;User Id=DBUser;password=Lualah8991;databa se=Viamura_at" providerName="System.Data.SqlClient" />--> </connectionStrings> <nhibernateSettings> <!-- List every session factory that will be needed; transaction management and closing sessions will be managed with the open-session-in-view module --> <sessionFactories> <clearFactories /> <sessionFactory name="WebCrawlerFactory" factoryConfigPath="D:\PROJEKTI\crawl er\WebCrawlerSuite\ViaMura.Web\NHibe rnate.config" isTransactional="true" /> <!--<sessionFactory name="WebCrawlerFactory" factoryConfigPath="C:\_ZAGON\ViaMura \CurrencyApp\at\NHibernate.config" isTransactional="true" />--> </sessionFactories> </nhibernateSettings>
how can i programatically edit WebCrawlerFactory? I am using
Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None);

Ans


private void UpdateConfig(string key, string value, string fileName) { var configFile = ConfigurationManager.OpenExeCon figuration(fileName);
configFile.AppSettings.Settings [key].Value = value;
configFile.Save(); }
Where: fileName is the full path + application name (c:\project\application.exe)
In your case, change the AppSetting by Sections:
configFile.Sections["nhibernat eSettings"]

If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website

0 comments:

Post a Comment