如何使用COnfigurationManager类读取和写入设置文件?ConfigurationManager类
回答
我可以尝试并给你细分,但真的以下链接,全部由Jon Rista编写,是我发现的有关System.Configuration命名空间的最佳资源。
Unravelling the Mysteries of .NET 2.0 Configuration
感谢您的链接。最终的链接包含对machine.config文件的引用。该文件包含我在下面的SpaceCracker评论中提到的“流氓”字符串。我相信我已经想出了.NEt可执行文件的配置管理系统。 – abhi 2010-07-18 13:33:31
检查以下
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
http://www.codeproject.com/KB/cs/SystemConfiguration.aspx
我遇到的一件事是,当我通过connectionstrings部分执行循环时,会出现一个流氓字符串,我不知道这个流氓字符串是如何填充的。例如,我的连接字符串部分有 a> prod b> dev c>其中包含字符串 。 当我通过connectionStrings节循环时,使用此代码。 (ConfigurationManager.ConnectionStrings中的ConnectionStringSettings键) Console.WriteLine(“ConKey:{0},Value:{1}”,key.Name,key.ConnectionString.ToString()); } 我得到4个字符串。 – abhi 2010-07-17 20:54:28
一两件事,可能会赶你出去是访问您必须手动添加到System.Configuration参考ConfigurationManager中类。 System.Configuration命名空间被分割到多个程序集中 - 默认情况下你只能得到其中的一部分。
Space Cracker发布了一些很好的链接,但也有一种方法可以编写强类型的配置部分,我在几年前写了这些部分 - Configuring a .NET 2.0 Application Using the ConfigurationSection class。我从来没有见过其他人使用过强类型的ConfigurationSections,但一旦你习惯了他们,他们非常有用。
- 1. ConfigurationManager&Static类
- 2. 静态ConfigurationManager访问类操作
- 3. ConfigurationManager类和按需配置更改
- 4. ConfigurationManager未找到
- 5. ConfigurationManager vs变量
- 6. ConfigurationManager的替代
- 7. App.config和ConfigurationManager
- 8. 如何在类库中使用ConfigurationManager类项目类型
- 9. c#.net ConfigurationManager坏了
- 10. envdte configurationmanager项目StartOptions
- 11. ConfigurationManager立即给出TypeInitializationException
- 12. 如何使用ConfigurationManager? (Microsoft.IdentityModel.Protocols)
- 13. 为什么没有ConfigurationManager?
- 14. .NET ConfigurationManager中的app.config混乱
- 15. C#ConfigurationManager中的问题
- 16. 使用OWIN TestServer和ConfigurationManager
- 17. VS 2017中的ConfigurationManager问题
- 18. 编写一个交叉框架类,ConfigurationManager和ConfigurationSettings
- 19. 引用程序集中的ConfigurationManager
- 20. ConfigurationManager ConnectionStrings在哪里获取其值?
- 21. 如何通过ConfigurationManager写入User.Config文件?
- 22. 使用ConfigurationManager中无法读取配置
- 23. ConfigurationManager ConnectionString抛出错误并返回空
- 24. 无法获得对ConfigurationManager的引用
- 25. ConfigurationManager中不保存设置exe.config
- 26. 如何在LINQPad中模拟ConfigurationManager
- 27. 处理web.config文件 - 替代ConfigurationManager
- 28. 如何使用ConfigurationManager解析app.config?
- 29. ASP MVC - ConfigurationManager无法找到Appsettings
- 30. 检测的appSettings的重载在ConfigurationManager中
有你来这里之前一派? – 2010-07-17 14:54:49
是的,我当然有。我有几个链接,我试过了。我也参考Andrew Troelson编写的一本名为“Pro C#2008和.NET 3.5 Platform”的书。我正在尝试那本书中的例子。这本书说,app.exe.config每次被覆盖,我编译。我在VS 2010中没有遇到过这种情况。 – abhi 2010-07-17 21:24:51