XML文件格式如下
<appSettings>
    <add key="webservice_url" value="http://localhost:1885/Acmeway.Business.Webservices/Service.asmx" />
 <\appSettings>
怎么读出http://localhost:1885/Acmeway.Business.Webservices/Service.asmx信息

解决方案 »

  1.   

    app.config有专门的类可以处理。ConfigruationManager
      

  2.   

    例:有程序a,b 
    B要用A的配置文件,能用ConfigruationManager吗
      

  3.   

    string webservice_url = System.Configuration.ConfigurationSettings.AppSettings["webservice_url"];
      

  4.   

    例:有程序a,b 
    B要用A的配置文件,能用ConfigruationManager吗
      

  5.   

    ConfigruationManager 好象只对 WEB.CONFIG文件有效,
    lz可以有以下2中方式处理
    1.AB程序公用一个WEB.CONFIG文件,如果有2种以上的连接字符串可以用
    <appSettings> 
        <add key="webservice_url1" value="http://localhost:1885/Acmeway.Business.Webservices/Service.asmx" /> 
    <add key="webservice_url2" value="http://localhost:1885/Acmeway.Business.Webservices/Service.asmx" /> 
    <\appSettings> 
        用 System.Configuration.ConfigurationSettings.AppSettings["webservice_url1"];
           System.Configuration.ConfigurationSettings.AppSettings["webservice_url1"];
        读出
    2.单独读xml文件,也就先用一个XML保存连接字符串信息,然后读该信息,该方法很多
      

  6.   

    ConfigurationManager.AppSettings["webservice_url"]
      

  7.   

    XmlDocument doc = new XmlDocument();
    doc.Load(file);
    XmlNode node = doc.SelectSingleNode("/appSettings/add");Console.WriteLine(node.Attributes["value"].Value);
      

  8.   

    ConfigurationManager.AppSettings["webservice_url"]
      

  9.   

    lovefootball :
    XmlNode node = doc.SelectSingleNode("/appSettings/add"); 
    node是NULL的
    我的格式
    <appSettings>
        <add key="webservice_url" value="http://localhost:1885/Acmeway.Business.Webservices/Service.asmx" />
      

  10.   

    自己解决
     XmlDocument doc = new XmlDocument();
                doc.Load(Application.StartupPath + @"\Acmeway.Business.Main.exe.config");
                XmlNodeList DocdNodeNameArr = doc.DocumentElement.ChildNodes;//文档节点名称数组
                foreach (XmlElement DocXmlElement in DocdNodeNameArr)
                {
                    if (DocXmlElement.Name.ToLower() != "appsettings") continue;//找到名称为 appsettings 的节点                XmlNodeList KeyNameArr = DocXmlElement.ChildNodes;//子节点名称数组
                    if (KeyNameArr.Count <= 0) continue;                string KeyName = "";
                    string KeyValue = "";
                    for (int i = 0; i < KeyNameArr.Count; i++)
                    {
                        if (!(KeyNameArr[i] is XmlElement)) continue;                    XmlElement xmlElement = KeyNameArr[i] as XmlElement;
                        if (xmlElement.Attributes.Count <= 0) continue;                    KeyName = xmlElement.Attributes["key"].InnerXml;//键值
                        switch (KeyName)
                        {
                            case "webservice_url":
                                KeyValue = xmlElement.Attributes["value"].Value;
                                break;
                        }
                    }
                }