读配置文件的问题,为何C#中的配置文件只能命名App.config?在线等!! As far as I know, the answer is no. It has to be App.config, which will be renamed to "youapp.exe.config" and copied to bin/debug (or bin/release) directory. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是楼上说的,IDE默认用App.config,编译的时候自动会根据生成的exe文件来命名。如你的程序是hello.exe,那么IDE会自动在同一目录下生成hello.exe文件。你用其他的ide找不到。 ConfigurationSettings.AppSettings只能读取默认的App.config文件名,你可以通过右键点击项目->添加新项->应用程序配置文件添加一个配置文件。 就是楼上说的,IDE默认用App.config,编译的时候自动会根据生成的exe文件来命名。如你的程序是hello.exe,那么IDE会自动在同一目录下生成hello.exe文件。你用其他的ide找不到。------------------------------------------------------------------------是这样吗?我现在的exe文件名是loader.exe,我希望config文件名是loader.exe.config,但是只能读出App.config的内容。 如果你的exe文件名是loader.exe,config文件名是loader.App.config. 我现在的exe文件名是loader.exe,我希望config文件名是loader.exe.config---------------------------------------------------你生成exe文件的文件夹内肯定是loader.exe.config 如果更改了exe文件名,同时也更改config的文件名,只要一致就可以。 楼上的几位大哥,我现在的exe文件名就是loader.exe,但是就只认App.config,太奇怪了。况且IDE生成的config文件不在exe文件的文件夹内,而在该工程的目录下。 private string appPath = Application.ExecutablePath+".config";private XmlDocument configData=new XmlDocument();private string GetAppValue(string key) { return configData.SelectSingleNode("/configuration/appSettings/add[@key='"+key+"']").Attributes["value"].Value; }========================strText=GetAppValue("date")===========================app.config必须在源码目录下,在ide里用添加方式加入<?xml version="1.0" encoding="utf-8" ?><configuration> <appSettings> <!-- head --> <add key="date" value="[06.16]" /> <add key="department" value="[EPOP]" /> </appSettings></configuration> 我一开始就说过了(第一帖,呵呵),流程是这样的: 假设你的Project叫Foobar,位于E:\Foobar,App.config是在你Project的目录下,就是E:\Foobar。Visual Studio在编译完成后会把这个文件重命名为Foobar.exe.config,然后copy到E:\Foobar\bin\Debug(或Release),Foobar.exe运行的时候,实际使用的是Foobar.exe.config。不信的话,你可以在编译结束后,用notepad打开Foobar.exe.config,改动一下里面的内容,再运行一下Foobar.exe看看。 richTextBox中同时打字和粘贴图片,结果图片变成最前面的一个空格 C#是用什么控件可以一次保存多条数据到数据库 看得我晕.....休息.... 类名中的:,起什么作用 TCP模拟HTTP协议,无法发送请求命令 如何给datagrid排序 socket 侦测客户端状态 如何利用C#将一个XML文件作为一个整体存入SQL2005中的XML字段中 C# 有没有类似QT 中的Graphics View Framework 的东西 存储到SQL Server中的文本显示到DataList中不能显示回车换行?请指点迷津了 为什么需要这样"{0}"?? 用C#如何读写配置文件?
------------------------------------------------------------------------
是这样吗?我现在的exe文件名是loader.exe,我希望config文件名是loader.exe.config,但是只能读出App.config的内容。
---------------------------------------------------你生成exe文件的文件夹内肯定是loader.exe.config
private XmlDocument configData=new XmlDocument();
private string GetAppValue(string key)
{
return configData.SelectSingleNode("/configuration/appSettings/add[@key='"+key+"']").Attributes["value"].Value;
}========================
strText=GetAppValue("date")
===========================
app.config必须在源码目录下,在ide里用添加方式加入<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!-- head -->
<add key="date" value="[06.16]" />
<add key="department" value="[EPOP]" />
</appSettings>
</configuration>