• 网站的配置文件XML读写


    网站的配置信息一般都写入到XML中,以下是简单的对xml的读写操作,仅供参考。

    读操作:
            XmlDocument xmlDoc = new XmlDocument();
                 XmlReaderSettings settings = new XmlReaderSettings();
                 settings.IgnoreComments = true;//忽略文档里面的注释
                 var path = HttpContext.Server.MapPath("../../SiteConfig/Siteconfig.xml");//获取文件路径
                 var myXDocument = XDocument.Load(path);
                 EditWebConfigViewModel siteconfigModel = new EditWebConfigViewModel();
                 siteconfigModel.WebName = myXDocument.Element("SiteConfig").Element("WebName").Value;
                 siteconfigModel.CompanyName = myXDocument.Element("SiteConfig").Element("CompanyName").Value;
                 siteconfigModel.Address = myXDocument.Element("SiteConfig").Element("Address").Value;
                 siteconfigModel.Tel = myXDocument.Element("SiteConfig").Element("Tel").Value;
                 siteconfigModel.Email = myXDocument.Element("SiteConfig").Element("Email").Value;
                 siteconfigModel.RecordNumber = myXDocument.Element("SiteConfig").Element("RecordNumber").Value;
                 siteconfigModel.SeoTitle = myXDocument.Element("SiteConfig").Element("SeoTitle").Value;
                 siteconfigModel.SeoKey = myXDocument.Element("SiteConfig").Element("SeoKey").Value;
                 siteconfigModel.SeoDescription = myXDocument.Element("SiteConfig").Element("SeoDescription").Value;
                 siteconfigModel.Copyright = myXDocument.Element("SiteConfig").Element("Copyright").Value;
    写操作:
             var path = HttpContext.Server.MapPath("../../SiteConfig/Siteconfig.xml");
                    var myXDocument = XDocument.Load(path);
                    myXDocument.Element("SiteConfig").Element("WebName").Value = editWebConfig.WebName;
                    myXDocument.Element("SiteConfig").Element("CompanyName").Value = editWebConfig.CompanyName;
                    myXDocument.Element("SiteConfig").Element("Address").Value = editWebConfig.Address;
                    myXDocument.Element("SiteConfig").Element("Tel").Value = editWebConfig.Tel;
                    myXDocument.Element("SiteConfig").Element("Email").Value = editWebConfig.Email;
                    myXDocument.Element("SiteConfig").Element("RecordNumber").Value = editWebConfig.RecordNumber;
                    myXDocument.Element("SiteConfig").Element("SeoTitle").Value = editWebConfig.SeoTitle;
                    myXDocument.Element("SiteConfig").Element("SeoKey").Value = editWebConfig.SeoKey;
                    myXDocument.Element("SiteConfig").Element("SeoDescription").Value = editWebConfig.SeoDescription;
                    myXDocument.Element("SiteConfig").Element("Copyright").Value = editWebConfig.Copyright;
                    myXDocument.Save(path);
  • 相关阅读:
    04.安全-TLS1.2连接过程
    02.安全-证书和CA
    01.安全-加密
    00.https基本
    00.二叉树基本
    二分查找01.基本二本查找及其变种
    01.数据结构资料,时间复杂度空间复杂度(数据结构算法基本)
    从 CentOS 8 平滑迁移至 CentOS Stream
    identityserver使用记录
    vs2019 使用私钥进行连接时出错 ssh连接报错
  • 原文地址:https://www.cnblogs.com/WZH75171992/p/4643267.html
Copyright © 2020-2023  润新知