XML文件内容设置

同样是看别人的代码:

先取出要设置的信息:

代码
private void muItmSave_Click(object sender, EventArgs e)
        {
            FileAccess fAcc 
= new FileAccess();
            
int temp = cmboxDate.SelectedIndex + 1;
            Dictionary
<stringstring> dic = new Dictionary<stringstring>();
            dic.Add(
"MoneyDigits", textBox1.Text);
            dic.Add(
"RateDigits", textBox2.Text);
            dic.Add(
"ListCount", textBox3.Text);
            dic.Add(
"DateFormat", temp.ToString());
            
try
            {
                //引用设置方法
                fAcc.SetAppSetting(dic);
                
if (1==FileAccess.InitConfig())
                {
                    MessageBox.Show(
"读取配置文件错误");
                    
return;
                }
            }
            
catch (Exception ex)
            {
                
//MsgManager.NormalMsg("错误", "0011");
                LogWrite.WriteLogfile(ex.Message);
                MsgManager.Show(
"0011");
                
return;
            }
      }

 

文件设置方法:

 

代码
/// <summary>
        
/// 设置配置文件信息
        
/// </summary>
        
/// <param name="values"></param>
        public void SetAppSetting(Dictionary<stringstring> values)
        {
            
//定义Xml文档对象
            XmlDocument settings = new XmlDocument();
            
//打开XML配置文件
            StreamReader sr = new StreamReader(GlobalCache.Instance.ConfigFile);
            
//Load the config file into the XmlDocument object
            settings.Load(sr);
            
//关闭读文件流
            sr.Close();
            
//查找XML节点
            foreach (string key in values.Keys)
            {
                
foreach (XmlNode node in settings["configuration"]["appSettings"])
                {
                    
//查找匹配的节点
                    if (node.Attributes != null && string.Compare(key, node.Attributes["key"].Value) == 0)
                    {
                        node.Attributes[
"value"].Value = values[key];
                        
break;
                    }
                }
            }            
            
//保存文件内容
            settings.Save(GlobalCache.Instance.ConfigFile);
        }

 

 附加XMl文件内容:

代码
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
<appSettings>
      
<add key="MoneyDigits" value="2"></add>
      
<add key="RateDigits" value="5"></add>
      
<add key="DateFormat" value="2"></add>
      
<add key="ListCount" value="10"></add>
      
<add key="SysName" value="移动办公室"></add>
      
<add key="SkinName" value="yellowskin"></add>
      
<add key="LoginSkin" value="blackskin"></add>
      
      
<add key="LogFileName" value="SysLog.ini"></add>
      
<add key="LogBackPath" value="LogBack"></add>
    
<add key="filePath" value="http://127.0.0.1:8088/mobileoffice"></add>
    
<add key="savefileUrl" value="\file"></add>

      
<add key="ServicesPath" value="http://127.0.0.1:8088/MobileOffice/services/"></add>
      
      
<add key="ApprovalServices" value="http://127.0.0.1:8088/MobileOffice/services/ApproveServicePro"></add>
      
<add key="ReprotServices" value="http://127.0.0.1:8088/MobileOffice/services/ReportServicePro"></add>
      
<add key="CommonServices" value="http://127.0.0.1:8088/MobileOffice/services/CommonServicePro"></add>
      
<add key="CollWorkServices" value="http://127.0.0.1:8088/MobileOffice/services/CollWorkServicePro"></add>
      
<add key="LoansManggerServices" value="http://127.0.0.1:8088/MobileOffice/services/LoansManageServicePro"></add>
      
<add key="FinanceServices" value="http://127.0.0.1:8088/MobileOffice/services/FinanceManageServicePor"></add>
      
<add key="BankDynamicServices" value="http://127.0.0.1:8088/MobileOffice/services/BankDynamicServicePro"></add>
      
<add key="ServiceTimeout" value="6000"></add>
      
      
<add key="InternetUrl" value="http://microsof-qlavz2/SQLMobileWeb/sqlcesa30.dll"/>
      
<add key="InternetLogin" value="NORTHAMERICA\rtiffany"/>
      
<add key="InternetPassword" value="mag1nec"/>
      
<add key="CompressionLevel" value="1"/>

      
<add key="SQLEVDatabase" value="Data\MobileDb.sdf"/>
      
<add key="SQLEVPassword" value="sa"/>

    
<add key="UpdateVersionNum" value="1.0"></add>
    
<add key="UpdateConfigFile" value="http://66.66.1.2:8088/MobileOffice/File/UpdateConfig.txt"></add>
    
<add key="UpdateFileName" value="Update.exe"></add>

  
</appSettings>
</configuration>

 

 

posted @ 2010-03-06 09:39  古史漫谈  阅读(400)  评论(0编辑  收藏  举报