更新app.config文件編程與使用ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)以編程方式更新app.config文件;
配置配置= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
這是我的XML
<configuration>
<configSections>
<section name="nhibernateSettings" type="ProjectBase.Data.OpenSessionInViewSection, ProjectBase.Data" />
</configSections>
<appSettings>
<add key="NHibernateConfigPath" value="D:\PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web\NHibernate.config" />
<!--<add key="NHibernateConfigPath" value="C:\_ZAGON\ViaMura\CurrencyApp\at\NHibernate.config" />-->
<add key="ClientSettingsProvider.ServiceUri" 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;database=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\crawler\WebCrawlerSuite\ViaMura.Web\NHibernate.config" isTransactional="true" />
<!--<sessionFactory name="WebCrawlerFactory" factoryConfigPath="C:\_ZAGON\ViaMura\CurrencyApp\at\NHibernate.config" isTransactional="true" />-->
</sessionFactories>
</nhibernateSettings>
我如何編程編輯WebCrawlerFactory?我正在使用
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
您可以使用XPATH做到這一點,我做n沒有一個例子在這裏,但我已經做了這個使用XPATH更新我的web.config文件中的部分做一個谷歌搜索更新配置部分使用XPATH C# – MethodMan 2011-12-15 16:11:09
東西是這樣的:http://patelshailesh.com/index.php/update -web-config-programmatically – senzacionale 2011-12-15 16:38:22
看看我的例子我發佈了一個正確的repsonse爲以前的用戶.. [changeConfigFile運行時](http://stackoverflow.com/questions/8130085/opening-the-machine-base- web-config-64bit-through-code/8142160#8142160) – MethodMan 2011-12-15 17:43:40