Web site configuration file XML Read-write

Source: Internet
Author: User
Tags httpcontext

Web site configuration information is generally written to the XML, the following is a simple read and write operation of XML, for reference only.

read operation: XmlDocument xmldoc=NewXmlDocument (); XmlReaderSettings Settings=Newxmlreadersettings (); Settings. Ignorecomments=true;//Ignore comments inside the document             varPath = HttpContext.Server.MapPath (".. /.. /siteconfig/siteconfig.xml"); // Get file path               varMyxdocument =xdocument.load (path); Editwebconfigviewmodel Siteconfigmodel=NewEditwebconfigviewmodel (); 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;
Write operation:
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);

Web site configuration file XML Read-write

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.