网站的配置信息一般都写入到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);

网站的配置文件XML读写的更多相关文章

  1. .Net MVC 网站中配置文件的读写

    网站中有很多需要设置的内容,像网站信息,注册设置,上传设置等.如果保存在数据库中需要单独建张表,表中只有一条记录,这样会让数据库很臃肿,而且频繁存取数据库的效率也是个问题.而保存在config文件里是 ...

  2. C# 配置文件Xml读写

    分析xxx.exe.config文件: <?xml version="1.0" encoding="utf-8"?> <configurati ...

  3. C# XML读写实例

    一.使用System.Xml 实例:完成如下格式配置文件的读写操作: <?xml version="1.0" encoding="UTF-8"?> ...

  4. XML读写工具

    import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import j ...

  5. 配置文件Java读写

    今天把配置文件的Bug修复了,总结一下Java配置文件如何读写 配置文件的格式 以.properties后缀结尾,内容不出现空格和双引号 //config.properties Driver=com. ...

  6. Spring MVC的配置文件(XML)的几个经典案列

    1.既然是配置文件版的,那配置文件自然是必不可少,且应该会很复杂,那我们就以一个一个的来慢慢分析这些个经典案列吧! 01.实现Controller /* * 控制器 */ public class M ...

  7. 创建Google网站地图Sitemap.xml

    Sitemap.xml是google搞出来的,也就是网站地图,不过这个网站地图是用xml写的,而且要按google的标准来写,并且要将写出来的这个文件sitemap.xml上传到自己的服务器空间中去. ...

  8. 【Python】Python XML 读写

    class ACTIVE_FILE_PROTECT_RULE_VIEW(APIView): renderer_classes = (JSONRenderer, BrowsableAPIRenderer ...

  9. .Net 读取配置文件 xml

    直接解析XML文件 1.System.Xml.Linq命名空间下提供可以使用linq查询的类,使用linq to xml读取也很方便. 2.还可以使用System.Xml.Serialization类 ...

随机推荐

  1. 【好文翻译】一步一步教你使用Spire.Doc转换Word文档格式

    背景: 年11月,微软宣布作为ECMA国际主要合作伙伴,将其开发的基于XML的文件格式标准化,称之为"Office Open XML" .Open XML的引进使office文档结 ...

  2. Eclipse中SVN的安装步骤(两种)和用法

    一.给安装EclipseSVN,最常见的有两种方式:手动方式和使用安装向导方式.详细过程例如以下: 方式一:手动安装 1.从官网下载site-1.6.9.zip文件,网址是:subclipse.tig ...

  3. AJAX responseText vs responseXML

    AJAX------>本质 Request/Response(Server)模式 response的形式 responseText--------->获得字符串形式的响应数据. ----- ...

  4. [Angular2 Form] Group Inputs in Angular 2 Forms with ngModelGroup

    The ngModelGroup directive allows you to group together related inputs so that you structure the obj ...

  5. MySql 日期格式化函数date_format()

    mysql> select date_format(now(),'%Y'); +-------------------------+ | date_format(now(),'%Y') | +- ...

  6. 深入理解Redis中的主键失效及其实现机制

    参考:http://blog.sina.com.cn/s/articlelist_1221155353_0_1.html 作为一种定期清理无效数据的重要机制,主键失效存在于大多数缓存系统中,Reids ...

  7. Linux中/usr与/var目录详解

    /usr文件系统 /usr 文件系统经常很大,因为所有程序安装在这里. /usr 里的所有文件一般来自Linux distribution:本地安装的程序和其他东西在/usr/local 下.这样可能 ...

  8. 【源码】基于SQLite实现CMS论坛(BBS)----附件SQLite可视化界面客户端

              使用说明:管理员账号:admin  密码:523523523   一.  账号管理(登陆注册审核) 1.账号注册 url:/BBS/Account/pregister.aspx 2 ...

  9. A C

    Problem Description Are you excited when you see the title "AC" ? If the answer is YES , A ...

  10. solr中通过SFTP访问文件建立索引

    需求: 从oracle数据库中根据记录的文件名filename_html(多个文件以逗号隔开),文件路径path,备用文件名bakpath中获取 主机172.21.0.31上对应的html文件内容,并 ...