如何查找webconfig文件中"pwd"的位置?

解决方案 »

  1.   

    只能读出ConnectionString的值,也就是value中的类容,你必须自己分解这个字符串。然后修改对应的项目,在保存回去!
      

  2.   

    来了
    赟([email protected]) says:
    就是我在web.config中添加的连接字符串
    赟([email protected]) says:
    <add key="ConnectionString" value="PWD=sa;DSN=ss;UID=sa;DATABASE=db;>
     Just be yourself , and every thing will be fine.  says:
    分开存放不就可以了
    赟([email protected]) says:
    什么意思?
     Just be yourself , and every thing will be fine.  says:
    <add key="PWD" value="sa"/> Just be yourself , and every thing will be fine.  says:
    <add key="UID" value="sa"/> Just be yourself , and every thing will be fine.  says:
    了解??
    赟([email protected]) says:
    我知道
    赟([email protected]) says:
    我的意思是说我怎么在文件中找到相应的位置?
    赟([email protected]) says:
    因为我们随时有可能修改web.config文件,位置随时也会变
     Just be yourself , and every thing will be fine.  says:
    找到<add key="ConnectionString" value="PWD=sa;DSN=ss;UID=sa;DATABASE=db;>
    这个节点吗??
    赟([email protected]) says:
    也可以这么说
    赟([email protected]) says:
    我现在是纯粹用文件seek的方式,在固定的位置重新写信息的方式来写的
     Just be yourself , and every thing will be fine.  says:
    这个简单
    赟([email protected]) says:
    你有什么高见?
     Just be yourself , and every thing will be fine.  says:
    XmlDocument  xmldoc = new XmlDocument();
     Just be yourself , and every thing will be fine.  says:
    xmldoc.Load("web.config");
    赟([email protected]) says:
    然后呢?读写的时候呢?
    赟([email protected]) says:
    我没有写过xml的
     Just be yourself , and every thing will be fine.  says:
    XmlNode n1 = xmldoc.SelectSingleNode("//configureation/appSettings/add[@key='ConnectionString']");
     Just be yourself , and every thing will be fine.  says:
    到这里你就取到了这个节点
     Just be yourself , and every thing will be fine.  says:
    下面是操作
     Just be yourself , and every thing will be fine.  says:
    string sConn = n1.Attributes["value"].InnerText;
     Just be yourself , and every thing will be fine.  says:
    这个sConn就是连接字串
     Just be yourself , and every thing will be fine.  says:
    下面修改
     Just be yourself , and every thing will be fine.  says:
    n1.InnerText = "Test";
     Just be yourself , and every thing will be fine.  says:
    错了
     Just be yourself , and every thing will be fine.  says:
    应该是
    赟([email protected]) says:

     Just be yourself , and every thing will be fine.  says:
    n1.Attributes["value"].InnerText = "连接字串2";
     Just be yourself , and every thing will be fine.  says:
    最后不要忘了保存 , xmldoc.save("web.config");
     Just be yourself , and every thing will be fine.  says:
    还有什么疑问吗??
    赟([email protected]) says:
    好办法,我本来也认为用xml的方法简单,但是没有用过,刚才在网上问也没有人答
    赟([email protected]) says:
    http://community.csdn.net/Expert/topic/3472/3472453.xml?temp=.2168085
    赟([email protected]) says:
    接分吧