APP NEWS
读取程序集中的嵌入XML配置文件
场景例如:我有一个配置文件,是关于分站站点地址和数据库中的数据对应,需要在程序启动的时候进行读取。如下:Ericsth@Gmail.Com1.<?xmlversion="1.0"encoding="utf-8"?>2.<!--3.设置DoMain和商家编号前缀对应
场景例如:我有一个配置文件,是关于分站站点地址和数据库中的数据对应,需要在程序启动的时候进行读取。如下:
Ericsth@Gmail.Com
1.
2.
5.
6.
7.
8.
9.
10.
11.
点击文件的属性,设置为嵌入资源。
·引入此程序集(dll) ,在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. // 系统一启动,首先配置分站和城市Prov代码的映射
5. Assembly assembly = Assembly.Load(&程序集名称&);
6. Stream stream = assembly.GetManifestResourceStream(&程序集名称.DoMainMapping.cfg.xml&);
7. XmlDocument xmlDoc = null;
8. xmlDoc = new XmlDocument();
9. xmlDoc.Load(stream);
10.}
到此,就可以得到这个配置文件的信息!
关键词标签:嵌入XML配置






