如何多个WINFORM项目(多个EXE)共用APP.CONFIG?

zjkkkk 2008-04-02 05:57:03
加精
解决方案中有有好几个WINFORM项目,生成的EXE在同一个文件夹内,现在想让他们共享配置文件,就是APP.CONFIG文件,请问有办法解决吗?
...全文
1639 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
cuitht 2010-02-08
  • 打赏
  • 举报
回复
我也遇到這個問題了,而且已經解決,我也不再累述,見我的博客:http://blog.csdn.net/cuitht/archive/2010/02/08/5297616.aspx
youqi1984 2009-01-01
  • 打赏
  • 举报
回复
^ō^ 方法二(System.configuration.dll):


C# codeSystem.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);

string value = config.ConnectionStrings.ConnectionStrings["key"].ToString(); //使用范例..

config = null;

-------------------------------------------------------------------------------
在WinForm中根本没有ConfigurationManager,这个只是存在WebForm中.
App.config时WinForm中
wsp6188 2008-10-30
  • 打赏
  • 举报
回复
正好遇到这个问题,顶一下先!
wsp6188 2008-10-30
  • 打赏
  • 举报
回复
/// <summary>
/// 读取Ecms_cs.exe.config参数.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string getSystemParam(string name)
{
string configFileName = Application.StartupPath + "\\Ecms_cs.exe.config";//请根据实际情况修改
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(configFileName);
string configString = @"configuration/userSettings/Ecms_cs.Settings1/setting[@name='" + name + "']/value";//请根据实际情况修改
System.Xml.XmlNode configNode = doc.SelectSingleNode(configString);
if (configNode != null)
{
return configNode.InnerText;
}
return "";
}
请根据实际情况修改
twobug 2008-09-15
  • 打赏
  • 举报
回复
配置文件中大部分节点支持一个ConfigSource属性,这里面指定那个配置文件路径即可, appSettings使用file=...
CNBT 2008-09-07
  • 打赏
  • 举报
回复
对,使用这个方法完全可以,但是要注意那个参数exePath,他不是config文件的路径。
详细请看:http://www.cnblogs.com/bearhand/archive/2008/09/07/1279087.html
shinaterry 2008-04-04
  • 打赏
  • 举报
回复
完全可以
shinaterry 2008-04-04
  • 打赏
  • 举报
回复
完成可以
怫悰 2008-04-04
  • 打赏
  • 举报
回复
冒泡接分

好像记得有app.config可以包含子config的一说
shinaterry 2008-04-04
  • 打赏
  • 举报
回复
^ō^ 方法二(System.configuration.dll):

System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);

string value = config.ConnectionStrings.ConnectionStrings["key"].ToString(); //使用范例..

config = null;
zjkkkk 2008-04-03
  • 打赏
  • 举报
回复
shinaterry 2008-04-03
  • 打赏
  • 举报
回复
<推荐置精>
shinaterry 2008-04-03
  • 打赏
  • 举报
回复
^ō^ 加点分..

System.AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"指定 App.config 位置");
fengniumaxi 2008-04-02
  • 打赏
  • 举报
回复
建议把这个app.config文件放在BIN目录下,通过程序集来获取相应路径,之后都指定这个路径就OK了
lnwuyaowei 2008-04-02
  • 打赏
  • 举报
回复
写一个类,读写app.config文件,其它项目都通过这个类调用.
csharp_start 2008-04-02
  • 打赏
  • 举报
回复
直接读就是了.只要指定清楚路径.

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧