• 读写xml文件结点值


    public static  void UpdateConfig(string item,string itemvalue)
            
    {
                
    try
                
    {
                    
    //将连接字符串写入Web.config
                    System.IO.FileInfo fileInfo=new FileInfo(AppDomain.CurrentDomain.BaseDirectory+"DataBase.xml");

                    
    if(!fileInfo.Exists)
                        MessageBox.Show(
    "can't find the app.config");

                    XmlDocument doc
    =new XmlDocument();
                    doc.Load(fileInfo.FullName);
                        
    //doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                    
                    
    bool foundIt=false;

                    
    string connString=itemvalue;

                    
    string enCS=connString;//SecurityHelper.EncryptDBConnectionString(connString);

                    XmlNode no
    =doc.SelectSingleNode("//appSettings/add[@key='"+item+"']");
                    
    if(no!=null)
                    
    {
                        no.Attributes.GetNamedItem(
    "value").Value=enCS;
                        foundIt
    =true;
                    }


                    
    if(!foundIt)
                        MessageBox.Show(
    "can't find the connString setting ");
                    doc.Save(fileInfo.FullName);
                }

                
    catch(Exception ex)
                
    {
                    StreamWriter w
    =new StreamWriter(AppDomain.CurrentDomain.BaseDirectory+"log.txt",true);
                    w.WriteLine(
    "===in updata connstring=tjtj=====");
                    w.WriteLine(ex.ToString());
                    w.WriteLine(ex.StackTrace);
                    w.Close();
                }

            }

            
    public static  string  LoadConfig(string item)
            
    {
                
    string reval="";
                
    try
                
    {
                    
    //将连接字符串写入Web.config
                    System.IO.FileInfo fileInfo=new FileInfo(AppDomain.CurrentDomain.BaseDirectory+"DataBase.xml");

                    
    if(!fileInfo.Exists)
                        MessageBox.Show(
    "can't find the app.config");

                    XmlDocument doc
    =new XmlDocument();
                    doc.Load(fileInfo.FullName);
                    
    //doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                    
                    
    bool foundIt=false;
                    
                    

                    

                    XmlNode no
    =doc.SelectSingleNode("//appSettings/add[@key='"+item+"']");
                    
    if(no!=null)
                    
    {
                        reval
    =no.Attributes.GetNamedItem("value").Value;
                        
                        foundIt
    =true;
                    }


                    
    if(!foundIt)
                        MessageBox.Show(
    "can't find the connString setting ");                
                }

                
    catch(Exception ex)
                
    {
                    StreamWriter w
    =new StreamWriter(AppDomain.CurrentDomain.BaseDirectory+"log.txt",true);
                    w.WriteLine(
    "===in updata connstring=tjtj=====");
                    w.WriteLine(ex.ToString());
                    w.WriteLine(ex.StackTrace);
                    w.Close();                
                }

                
    return reval;
            }
  • 相关阅读:
    [转载]我的WafBypass之道(Misc篇)
    7.3 使用while 循环来处理列表和字典
    7-4__7-7练习
    7.2 while 循环
    第 7 章 用户输入和while 循环
    6.字典练习
    6.4 嵌套
    6.3 遍历字典
    6.2练习
    第 6 章 字典
  • 原文地址:https://www.cnblogs.com/lidune/p/546752.html
Copyright © 2020-2023  润新知