XmlDocument xDoc = new XmlDocument(); try { xDoc.Load(配置文件路径); XmlNode xNode; XmlElement xElem; xNode = xDoc.SelectSingleNode("//appSettings"); //补充,需要在你的app.config 文件中增加一下,<appSetting> </appSetting> xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + 读取的配置KEY+ "']"); if (xElem != null) return xElem.GetAttribute("value"); else return ""; } catch (Exception) { return ""; }