I遇到了两种情况:读文件夹中的aaa.exe.config文件(自己的项目中不存在);读我自己项目中的app.config文件。
...... 1)读文件夹中的aaa.exe.config文件(自己的项目中不存在) ConfigXmlDocument config_xml = new ConfigXmlDocument(); config_xml.Load(vdcPath + "aaa.exe.config"); NameValueCollection appSettings = ConfigurationManager.AppSettings; XmlNodeList list = config_xml.SelectNodes("/configuration/appSettings/add"); foreach (XmlNode node in list) { string name = node.SelectSingleNode("@key").InnerText; string value = node.SelectSingleNode("@value").InnerText; if (name.ToLower() == "service_uri") { string nsi = node.Attributes["value"].Value; //取得service_uri地址中ip的值 Regex patten_nsi = new Regex(@"^(?/w+)://(?[^/]+):(?/d+)?"); Match nsi_match = patten_nsi.Match(nsi); if (nsi_match.Success) { // MessageBox.Show("Match successful"); string nsi_ip = nsi_match.Groups["addr"].Value; string nsi_port = nsi_match.Groups["port"].Value; //this.txt_nsi.Text = nsi_ip; this.txt_nsi_port.Text = nsi_port; } } else if(){....} 2)读我自己项目中的app.config文件 RemotingConfiguration.Configure("app.config", false); NameValueCollection appSettings = ConfigurationManager.AppSettings; fileKey = appSettings["service_uri"]; Console.WriteLine("Key:{0}",fileKey);