XML文件内容设置

同样是看别人的代码:

先取出要设置的信息:

ExpandedBlockStart.gif 代码
private   void  muItmSave_Click( object  sender, EventArgs e)
        {
            FileAccess fAcc 
=   new  FileAccess();
            
int  temp  =  cmboxDate.SelectedIndex  +   1 ;
            Dictionary
< string string >  dic  =   new  Dictionary < string string > ();
            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 ;
            }
      }

 

文件设置方法:

 

ExpandedBlockStart.gif 代码
///   <summary>
        
///  设置配置文件信息
        
///   </summary>
        
///   <param name="values"></param>
         public   void  SetAppSetting(Dictionary < string string >  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文件内容:

ExpandedBlockStart.gif 代码
<? 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 >

 

 

转载于:https://www.cnblogs.com/gjs85/archive/2010/03/06/1679549.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值