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