C# 如何从c中的服务器位置获取app.config值#
我想在程序中读/写(和使用)应用程序的配置文件 服务器的app.config 节未返回服务器应用程序配置的连接字符串,该字符串为[Catalog]。 有人能帮我吗C# 如何从c中的服务器位置获取app.config值#,c#,configuration,C#,Configuration,我想在程序中读/写(和使用)应用程序的配置文件 服务器的app.config 节未返回服务器应用程序配置的连接字符串,该字符串为[Catalog]。 有人能帮我吗 ConnectionStringsSection()。ConnectionStrings提供配置中所有连接字符串的集合 遍历以获得所需的结果 <configSections> <section /> </configSections> <connectionString
<configSections>
<section />
</configSections>
<connectionStrings>
<add name="catalogue" connectionString="Data Source=abc\_SQLSERVER;Initial
Catalog=Catalogue;Integrated Security=False;Persist Security Info=False; user ID=sa;password=****;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<dataConfiguration defaultDatabase="Catalogue"/>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<appSettings>
</appSettings>
</configuration>
string pathString = System.IO.Path.Combine(CentralizedPath, "abc.exe.config");
Configuration config = ConfigurationManager.OpenExeConfiguration(pathString);
ConnectionStringsSection section = config.GetSection("connectionStrings") as
ConnectionStringsSection;
ConnectionStringSettingsCollection collection= config.ConnectionStringsSection().ConnectionStrings;
foreach(ConnectionStringSettings css in collection)
{
string output= css.Name;
}