zoukankan      html  css  js  c++  java
  • XML操作

    string filename = System.Windows.Forms.Application.ExecutablePath + ".config";
                    XmlDocument doc = new XmlDocument();
                    doc.Load(filename);
    
                    XmlElement element = doc.SelectSingleNode("//appSettings/add[@key='Lang']") as XmlElement;
                    if (element == null)
                    {
                        var appElement = doc.SelectSingleNode("//appSettings");
                        if (appElement == null)
                        {
                            appElement = doc.CreateElement("appSettings");
                            doc.SelectSingleNode("/configuration").AppendChild(appElement);
                        }
    
                        element = doc.CreateElement("add");
                        var key = doc.CreateAttribute("key");
                        key.Value = "Lang";
    
                        var value = doc.CreateAttribute("value");
                        element.AppendChild(key);
                        element.AppendChild(value);
                        appElement.AppendChild(element);
                    }
                    element.GetAttributeNode("value").Value = CurrentLang.CultureInfo.Name;
                    doc.Save(filename);
    
     var configDir = new DirectoryInfo("./Config/Language/ServiceUri");
                FileInfo[] configFiles = configDir.Exists ? configDir.GetFiles() : new FileInfo[0];
    
                FileInfo item = null;
    
                if (languageName == "中文")
                {
                    item = configFiles.FirstOrDefault(f => System.IO.Path.GetFileNameWithoutExtension(f.Name) == "serviceuri_zh");
                }
                else
                {
                    item = configFiles.FirstOrDefault(f => System.IO.Path.GetFileNameWithoutExtension(f.Name) == "serviceuri_us");
                }
    
                if (item != null)
                {
                    var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName + ".config");
                    File.Copy(item.FullName, fileName, true);
                    ConfigurationManager.RefreshSection("system.serviceModel");
                    ConfigurationManager.RefreshSection("appSettings");
                }
    
  • 相关阅读:
    【dp】船
    【dp】PKU 1952 buy low,buy lower
    【dp】合唱队形
    【dp】导弹拦截
    【dfs】POJ1321 棋盘问题
    工程师工作与学习的模式
    如何进行大规模在线数据迁移(来自Stripe公司的经验)
    Laravel事件监听器listener与事件订阅者Subscriber的区别
    微信小程序时间处理问题
    [翻译] Facebook HHVM 团队封闭开发三周成果展
  • 原文地址:https://www.cnblogs.com/wywnet/p/4790706.html
Copyright © 2011-2022 走看看