Read the embedded XML configuration file in the Assembly.

Source: Internet
Author: User
Tags log4net

For example, I have a configuration file that corresponds to the address of the Substation Site and the data in the database and needs to be read when the program starts. As follows:

Ericsth@Gmail.Com
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- 
  3. Configure DoMain and merchant ID prefix
  4. -->
  5. <DoMain>
  6.     <SubMain name="qz" pre="01002"></SubMain>
  7.     <SubMain name="yw" pre="01003"></SubMain>
  8.     <SubMain name="wl" pre="01030"></SubMain>
  9.     <SubMain name="cq" pre="02001"></SubMain>
  10.     <SubMain name="cq" pre="02002"></SubMain>
  11. </DoMain>

Click the properties of the file and set it to an embedded resource.

  • Introduce this Assembly (dll) in Global. asax. cs:
Ericsth@Gmail.Com
  1. protected void Application_Start(object sender, EventArgs e)
  2. {
  3.     // log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("Log4Net.config"));
  4. // When the system is started, first configure the ing between the substation and the city Prov code
  5. Assembly assembly = Assembly. Load ("Assembly name ");
  6. Stream stream = assembly. GetManifestResourceStream ("assembly name. DoMainMapping. cfg. xml ");
  7.     XmlDocument xmlDoc = null;
  8.     xmlDoc = new XmlDocument();
  9.     xmlDoc.Load(stream); 
  10. }

At this point, you can get the information of this configuration file!

Related Article

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.