欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# 读取指定路径配置文件的方法

程序员文章站 2023-12-01 13:32:34
复制代码 代码如下:execonfigurationfilemap map = new execonfigurationfilemap();  &nbs...
复制代码 代码如下:

execonfigurationfilemap map = new execonfigurationfilemap();
            map.execonfigfilename = @"f:\app1.config"; ;
            configuration config = configurationmanager.openmappedexeconfiguration(map, configurationuserlevel.none);
            string connstr = config.connectionstrings.connectionstrings["connstr"].connectionstring;
            messagebox.show(connstr);
            string key = config.appsettings.settings["key"].value;
            messagebox.show(key);