日期:2014-05-19  浏览次数:20768 次

请问如何修改配置文件app.config的值

传入的参数为  
modifyXml( "IntervalTime ",   "60 ");
     
我的方法      
private   void   modifyXml(string   xmlkey,   string   xmlvalue)
                {
                        Assembly   ass   =   Assembly.GetExecutingAssembly();
                        string   fullPath   =   ass.Location.Substring(0,   ass.Location.LastIndexOf(@ "\ "));
                        fullPath   =   fullPath   +   @ "\CareHealth.vshost.exe.config ";
                        //MessageBox.Show(fullPath);
                        XmlDocument   xmldoc   =   new   XmlDocument();
                        xmldoc.Load(fullPath);
                        XmlNodeList   xnlist   =   xmldoc.SelectSingleNode( "configuration ").ChildNodes;

                        foreach   (XmlNode   xn   in   xnlist)
                        {
                                XmlElement   xe   =   (XmlElement)xn;
                                if   (xe.InnerXml.IndexOf( " <add   key=\ " "   +   xmlkey   +   "\ " ")   !=   -1)
                                {
                                        xe.SetAttribute( "value ",   xmlvalue);
                                        break;
                                }
                        }
                        xmldoc.Save(fullPath);
                }


配置文件
<?xml   version= "1.0 "   encoding= "utf-8 "   ?>
<configuration>
        <configSections>
                <sectionGroup   name= "applicationSettings "   type= "System.Configuration.ApplicationSettingsGroup,   System,   Version=2.0.0.0,   Culture=neutral,   PublicKeyToken=b77a5c561934e089 "   >
                        <section   name= "CareHealth.Settings1 "   type= "System.Configuration.ClientSettingsSection,   System,   Version=2.0.0.0,   Culture=neutral,   PublicKeyToken=b77a5c561934e089 "   requirePermission= "false "   />